You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@nutch.apache.org by "Sebastian Nagel (Jira)" <ji...@apache.org> on 2019/11/15 10:49:00 UTC

[jira] [Resolved] (NUTCH-2471) Returning a bare string meant to be application/json doesn't properly quote the string

     [ https://issues.apache.org/jira/browse/NUTCH-2471?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Sebastian Nagel resolved NUTCH-2471.
------------------------------------
    Resolution: Auto Closed

Closing 2.5 issues as branch is no longer maintained.

> Returning a bare string meant to be application/json doesn't properly quote the string
> --------------------------------------------------------------------------------------
>
>                 Key: NUTCH-2471
>                 URL: https://issues.apache.org/jira/browse/NUTCH-2471
>             Project: Nutch
>          Issue Type: Bug
>          Components: nutch server
>    Affects Versions: 2.3.1
>            Reporter: Ninaad Joshi
>            Priority: Blocker
>             Fix For: 2.5
>
>         Attachments: Ninaad.Joshi.BareStringJsonReturn.patch
>
>
> Nutch Server resources are JAX-RS resources and that they proclaims to produce JSON even for a resource method that returns a String...... 
> {code:java}
> @Produces({ MediaType.APPLICATION_JSON })
> public abstract class AbstractResource {
> .....
> }
> @Path("/config")
> public class ConfigResource extends AbstractResource {
> ...
> @GET
>   @Path("/{configId}/{propertyId}")
>   public String getProperty(@PathParam("configId") String configId,
>       @PathParam("propertyId") String propertyId) {
>     return configManager.getAsMap(configId).get(propertyId);
>   }
> }
> {code}
> the HTTP response indicates it is an application/json response, however the string returned is not properly quoted for JSON. We also get de-serialization errors on the client side.
> {noformat}
> server: Restlet-Framework/2.2.3
> date: Wed, 06 Dec 2017 10:30:13 GMT
> content-type: application/json; charset=UTF-8
> content-length: 21
> accept-ranges: bytes
> There was an error parsing JSON data
> Unexpected token B in JSON at position 0
> {noformat}
> The JAX-RS resources are configured to use JacksonJsonProvider for writing the JSON message body. JacksonJsonProvider.isWriteable() is indicating that it cannot write the value because _untouchables includes String.class. It appears String.class was put back into the _untouchables list as a result of a bug. That bug, however, appears to have been targeted at dealing with an XML issue, not a JSON issue. 
> It should have been ideally taken care by the Jackson providers. However, it's not and hence proposing this fix.
> * Create our own custom NutchJsonProvider based on JacksonJsonProvider and remove the String.class from the _untouchables
> * Register this NutchJsonProvider with NutchServer to be used while writing JSON message body 
> I have attached the patch along with this issue
> The other option is to JsonEscape the string and pad it with double quotes before returning. This has to be done at all places wherever string is returned as Json response and also is prone to errors in future if anybody misses this escaping and padding.
> There already is : [issue created on the JAX-RS|https://github.com/dropwizard/dropwizard/issues/231] 



--
This message was sent by Atlassian Jira
(v8.3.4#803005)