I have a nested JSON structure. I want to retrieve only a particular branch of the structure and ignore rest of the objects in the json. I am not sure on the approach to achieve this. Please suggest.
For example:
{
"prop1":"val1",
"prop2":{
"child":"childval"
},
"prop3":{
"child":"childval"
}
}
Here, I want to retrieve only prop3 along with prop1 ignoring prop2.
{
"prop1":"val1",
"prop3":{
"child":"childval"
}
}
Would it require the usage of jackson libraries?
2
Answers
If you’re using Jackson, it will deserialize only the stuff you define.
Here is some code (that uses lombok for the getters and setters).
First define classes that represent the JSON structure.
Here is code to deserialize the JSON from a String.
Any Java library for JSON (de)serialization should be able to handle this, but here is how you can achieve it using Jackson: