Oliver
Oliver

Reputation: 4193

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.

Upvotes: 7

Views: 19811

Answers (2)

Radouxca
Radouxca

Reputation: 144

If the goal is to ignore property ONLY by deserialization, but still serialize it (read-only), it is possible with @JsonIgnoreProperties(value={ "size" }, allowGetters= true).

More info here: https://fasterxml.github.io/jackson-annotations/javadoc/2.6/com/fasterxml/jackson/annotation/JsonIgnoreProperties.html#allowGetters()

Upvotes: 0

nutlike
nutlike

Reputation: 4975

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

Upvotes: 12

Related Questions