I have a model like that:
private String message;
private Integer errorCode;
private String data;
I get for example the following JSON from remote:
{"data": {"cat": "1.2.3.4", "ner": "80", "name": "pinta" }, "message" : "m", "errorCode" : 12}
When I deserialize this JSON, the message
and errorCode
variables gets the correct value. However I don't want to have the content of my data
variable interpreted. Instead, I want it to be the following string:
{"cat": "1.2.3.4", "ner": "80", "name": "pinta" }
After that, I will interpret it myself. How can I get this value of data
?
I would rather suggest that you do let data be bound to an intermediate object; usually this is either java.util.Map
or org.codehaus.jackson.JsonNode
(JSON Tree). And then you can access data any way you want; including easily converting to a POJO using ObjectMapper.convertValue(inputPojo, outputType)
).
Jackson issue 596 was created for the desired functionality described in the original question. Vote for it if you want it implemented.
The current solution available is to implement custom deserialization processing.
Also, the How can I include raw JSON in an object using Jackson? thread covers this topic.
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