I have a class as below.
class ExampleBean{
public String Name;
public JSONObject data;
}
And i have @GET handler which is as follows:
@GET
@Consumes({MediaType.APPLICATION_JSON})
public Response getData(ExampleBean dataBean)
{
// some usage code here
}
I want following json to be mapped to the ExmampleBean:
{
"Name":"Example",
"data":{
"hello":"world",
"some":"value"
}
}
Everything works perfectly if data was a type which had two public fields named hello and some. But since data is a JSONObject which doesn't actually have those fields or relevant setters it ends up throwing Unrecognized field "hello" (Class JSONObject), not marked as ignorable at [Source: org.apache.catalina.connector.CoyoteInputStream@17b9a4bf; line: 31, column: 18]
Try with JsonNode. It is working.
Class: com.fasterxml.jackson.databind.JsonNode
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With