[ 
https://issues.apache.org/jira/browse/TIKA-1311?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14017655#comment-14017655
 ] 

Tim Allison commented on TIKA-1311:
-----------------------------------

[~gagravarr], thank you, as always, for your thoughtful review!  I'll make 
updates and commit soon.

[~sergey_beryozkin], I appreciate all advice on JAX-RS.  I'm still trying to 
figure out how best to leverage the framework without reinventing the wheel. I 
googled some examples of GSON MBW, and I think we're effectively doing that now 
with the existing JSONMessageBodyWriter.  I modified that very slightly:

{code}
  @Override
  public void writeTo(Metadata metadata, Class<?> type, Type genericType, 
Annotation[] annotations,
      MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, 
OutputStream entityStream) throws IOException,
      WebApplicationException {
        try {
            Writer writer = new OutputStreamWriter(entityStream, "UTF-8");
            JsonMetadata.toJson(metadata, writer);
            writer.flush();
        } catch (TikaException e) {
            throw new IOException(e);
        }
        entityStream.flush();
  }
{code}

1) Is there a more efficient way of doing this?
2) We don't currently have an MBR, it seems fairly straightforward to me for 
clients to do something like this:

{code}
    Response response = WebClient.create(endPoint + 
META_PATH).type("application/msword")
        
.accept(MediaType.APPLICATION_JSON).post(ClassLoader.getSystemResourceAsStream(TikaResourceTest.TEST_DOC));
    Reader reader = new InputStreamReader((InputStream) response.getEntity());
    Metadata metadata = JsonMetadata.fromJson(reader);
{code}

...so, if we added an MBR, would it take less code than that or would it make 
it easier in the JAX-RS framework for others who actually know what they're 
doing? :)

> Centralize JSON handling of Metadata
> ------------------------------------
>
>                 Key: TIKA-1311
>                 URL: https://issues.apache.org/jira/browse/TIKA-1311
>             Project: Tika
>          Issue Type: Task
>            Reporter: Tim Allison
>            Priority: Minor
>         Attachments: TIKA-1311.patch
>
>
> When json was initially added to TIKA CLI (TIKA-213), there was a 
> recommendation to centralize JSON handling of Metadata, potentially putting 
> it in core.  On a recent bug fix (TIKA-1291), the same recommendation was 
> repeated especially noting that we now handle JSON/Metadata differently in 
> CLI and server.
> Let's centralize JSON handling in core and use GSON.  We should add a 
> serializer and a deserializer so that users don't have to reinvent that wheel.



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Reply via email to