[
https://issues.apache.org/jira/browse/NUTCH-2471?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Ninaad Joshi updated NUTCH-2471:
--------------------------------
Attachment: Ninaad.Joshi.BareStringJsonReturn.patch
> 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
> 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
> this [link
> bug|https://github.com/FasterXML/jackson-jaxrs-json-provider/issues/12]
> 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 : [link issue created on the
> JAX-RS|https://github.com/dropwizard/dropwizard/issues/231]
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)