I use Jackson, ObjectMapper.readValue(json, Class).
Have a class:
Component {
private String name;
private String someField;
private boolean show = true; // if false -> skip it object
}
and extensible class:
ExtendedComponent extends Component {
private List<Component> components = emptyList();// if all of object in list not showed -> skip field
}
and Complex class:
ComplexComponent extends Component {
ExtendedComponent component;
}
and json:
{
"complexComponent": {
"name": "complexName1",
"show": true,
"someField": "complex",
"extendedComponent": {
"components": [
{
"name": "someName1",
"show": true,
"someField": "someField"
},
{
"name": "someName2",
"show": false,
"someField": "someField"
},
{
"name": "someName3",
"show": true,
"someField": "someField"
}
]
}
}
}
How to get objects only with name someName1 and someName3 in ExtendedComponent ?
And how to get nullable ComplexComponent if all of components is not showed?
Depending on your version of jackson 2
@JsonInclude(Include.NON_DEFAULT)
or
@JsonInclude(Include.NON_EMPTY)
should do the trick.
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