I have the following json:
{ "id":"myid", "fields":{ "body":"text body" } }
which I want to deserialize into the following Java class:
class TestItem { private String id; private String body; public String getId() { return id; } public void setId(String id) { this.id = id; } public String getBody() { return body; } public void setBody(String body) { this.body = body; }
using the Jackson Json deserializer. This does not work because the body field is nested inside the fields inner class.
I cannot change the json structure, so is there any way (possibly using annotations), can I reassign the body field from TestItem.fields.body to TestItem.body ?
Edit: I had to say that this is part of a larger class hierarchy, and the goal of this exercise is to reduce its depth. In other words, I know that I CAN declare an inner class and then access it, but I did not achieve this.
java json jackson
Rupert bates
source share