0

Create api call looks like this:

@POST
@Path("/create")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response createEntity(EntityHolder<Entity> entity){}

If send a xml request it works fine but in case of Json payload it throws

ERROR  - caught an UnrecognizedPropertyException in the REST layer
21:35:36,836 INFO  [stdout] (http-/0.0.0.0:8080-1) com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "someProperty" (class com.sun.jersey.core.provider.EntityHolder), not marked as ignorable (0 known properties:

Looks like jackson is confusing EntityHolder with actual Entity class.

Himanshu Yadav
  • 13,315
  • 46
  • 162
  • 291
  • Yes it does. If you pay attention to the stack trace. jackson is considering `EntityHolder` as an actual `Entity` class. – Himanshu Yadav Aug 27 '14 at 02:24
  • Right. Which means jackson could not find `someProperty` of EntityHolder class. Instead of that jackson should have tried to find `someProperty` in `Entity` class. Isn't it? – Himanshu Yadav Aug 27 '14 at 02:44
  • Right. I see your point. My apologies and I will remove all my confusing comments. – ivan.sim Aug 27 '14 at 02:57

1 Answers1

1

I had the same problem.

I didn't find a good but a functional solution.

You can inject the Request with @Context and get the body content like this.

So, you can use jackson, gson or the implementation that you to prefer to unmarshall them.

That isn't the best solution, but it can help you.

Danilo Gomes
  • 571
  • 6
  • 13