Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to ignore a specific property when deserializing a JSON object?

I am working against a existing REST interface. One of the incoming JSON objects contains a property called size which I would like to ignore when deserializing this JSON object?

My standard behavior is to fail on unknown property, so I cannot configure the used object mapper to ignore unknown properties.

like image 589
Oliver Avatar asked Jul 29 '13 11:07

Oliver


People also ask

How do you ignore certain fields based on a serializing object to JSON?

If there are fields in Java objects that do not wish to be serialized, we can use the @JsonIgnore annotation in the Jackson library. The @JsonIgnore can be used at the field level, for ignoring fields during the serialization and deserialization.

How do you ignore fields in object mapper?

Jackson API provides two ways to ignore unknown fields, first at the class level using @JsonIgnoreProperties annotation and second at the ObjectMapper level using configure() method.

How do I ignore NULL values in JSON deserializing?

You can ignore null fields at the class level by using @JsonInclude(Include. NON_NULL) to only include non-null fields, thus excluding any attribute whose value is null. You can also use the same annotation at the field level to instruct Jackson to ignore that field while converting Java object to json if it's null.

How do you tell Jackson to ignore a field during deserialization?

Overview So when Jackson is reading from JSON string, it will read the property and put into the target object. But when Jackson attempts to serialize the object, it will ignore the property. For this purpose, we'll use @JsonIgnore and @JsonIgnoreProperties.


1 Answers

Add the annotation @JsonIgnoreProperties("size") to your POJO. See the JavaDoc for @JsonIgnoreProperties at fasterxml.github.io for more information.

like image 75
nutlike Avatar answered Sep 27 '22 22:09

nutlike