In this post, we will see how to resolve Using json key as a field in java object
Question:
I have the following json that I want to serialize and deserialize.Best Answer:
If the JSON property"name1"
is just an example and can vary (not known ahead of time), this might be what you’re looking for:@JsonAnyGetter
and @JsonAnySetter
which are generally for serializing/deserializing arbitrary properties that don’t have dedicated, named fields or getters.By using
@JsonIgnore
on the fields themselves, this allows the “dynamic” properties to shine through instead of the internal representation of the Java object.If you have better answer, please add a comment about this, thank you!
Source: Stackoverflow.com