For deserializing json with unknown field into an object there’s @JsonAnySetter.
But what if I read such json into my object, modify some known fields and write it back to json?
The unknown properties will be lost.
How do I handle such cases? Is it possible to map an object or do I have to read the data into a JsonNode or Map?
Unmarshalling into a custom java class has its advantages and disadvantages. It’s gives you nice static typing, but it’s well, static. The javadoc for
@JsonAnySettersuggests that it’s similar to JAXB’s@XmlAnyElement, but unlike@XmlAnyElement, the data objects don’t contain naming information, so it’s a one-way street.if you need to handle dynamic JSON streams, then you need to bite the bullet and use
MaporJsonNode.