Tuesday, 8 October 2013

Jackson - Ignoring fields

Jackson is used in Android to parse automatically JSON structure to java objects. There could be a POJO (Plain Old Java Object) or even just a class with several fields.

Sometimes we don't need all the data that comes with JSON, just few of them. In those cases, if the app uses Jackson and the POJO or other java class which does not contains the required methods get or fields, Jackson will return an error.

There is a way to set Jackson to ignore them.

Once instantiated, set the follow option:
// jackson 1.9 and before objectMapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false); // or jackson 2.0 objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);

StackOverFlow - Ignoring New fields on JSON objects using Jackson

No comments:

Post a Comment