tags:

views:

187

answers:

2

Hi,

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?

+1  A: 

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 @JsonAnySetter suggests 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 Map or JsonNode.

skaffman
A: 

There's this RFE for Jackson: http://jira.codehaus.org/browse/JACKSON-292 to add such a feature. Makes total sense when you think about it.

StaxMan
and the feature itself will go in 1.6 when it gets released
StaxMan