简体   繁体   中英

jackson - jackson parser not parsing the json

I have written a small web service and I am passing a JSON. On sending the request RESTClient says : Status Code: 415 Unsupported Media Type , thought I have put the header Content-Type: application/json.

The error message I am receiving on the server side is :

    [ERROR   ] A message body reader for Java class com.udm.jsons.JSON_Device, and Java type class com.udm.jsons.JSON_Device, and MIME media type application/json; charset=UTF-8 was not found.
The registered message body readers compatible with the MIME media type are:
application/json; charset=UTF-8 ->
  com.sun.jersey.json.impl.provider.entity.JSONJAXBElementProvider$App
  com.sun.jersey.json.impl.provider.entity.JSONArrayProvider$App
  com.sun.jersey.json.impl.provider.entity.JSONObjectProvider$App
  com.sun.jersey.json.impl.provider.entity.JSONRootElementProvider$App
  com.sun.jersey.json.impl.provider.entity.JSONListElementProvider$App
*/* ->
  com.sun.jersey.core.impl.provider.entity.FormProvider
  com.sun.jersey.core.impl.provider.entity.StringProvider
  com.sun.jersey.core.impl.provider.entity.ByteArrayProvider
  com.sun.jersey.core.impl.provider.entity.FileProvider
  com.sun.jersey.core.impl.provider.entity.InputStreamProvider
  com.sun.jersey.core.impl.provider.entity.DataSourceProvider
  com.sun.jersey.core.impl.provider.entity.XMLJAXBElementProvider$General
  com.sun.jersey.core.impl.provider.entity.ReaderProvider
  com.sun.jersey.core.impl.provider.entity.DocumentProvider
  com.sun.jersey.core.impl.provider.entity.SourceProvider$StreamSourceReader
  com.sun.jersey.core.impl.provider.entity.SourceProvider$SAXSourceReader
  com.sun.jersey.core.impl.provider.entity.SourceProvider$DOMSourceReader
  com.sun.jersey.json.impl.provider.entity.JSONJAXBElementProvider$General
  com.sun.jersey.json.impl.provider.entity.JSONArrayProvider$General
  com.sun.jersey.json.impl.provider.entity.JSONObjectProvider$General
  com.sun.jersey.core.impl.provider.entity.XMLRootElementProvider$General
  com.sun.jersey.core.impl.provider.entity.XMLListElementProvider$General
  com.sun.jersey.core.impl.provider.entity.XMLRootObjectProvider$General
  com.sun.jersey.core.impl.provider.entity.EntityHolderReader
  com.sun.jersey.json.impl.provider.entity.JSONRootElementProvider$General
  com.sun.jersey.json.impl.provider.entity.JSONListElementProvider$General
  com.sun.jersey.json.impl.provider.entity.JacksonProviderProxy

I have used the correct format on the server side alse :

@Path("/initiateProvisioning")
@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public ResponseInfo initiateProvisioning(JSON_Device device)

And I have generated the POJO for jackson use use jsonschema2pojo.org.Please help, I have been stuck for quiet !!!

Without the full request sent to the REST service, I can only make suppositions. Check if the header and the payload is UTF-8 encoded. Also, the payload must only be something like {...}

From what I can understand, you are posting JSON payload from the client and trying to receive it in the form of a POJO in one of your resource methods. You need a MessageBodyReader to achieve this. An implementation of this interface will contain the logic to convert your raw (JSON) input stream to a POJO (JSON_Device). JAX-RS run time will automatically invoke this when it's about to invoke your method and inject the returned object into your method (initiateProvisioning) parameter

JAX-RS javadocs - http://docs.oracle.com/javaee/6/api/javax/ws/rs/ext/MessageBodyReader.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM