7

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.

Oliver
  • 3,815
  • 8
  • 35
  • 63
  • Probably look at [this](http://stackoverflow.com/questions/11232045/serialization-and-deserialization-with-jackson-how-to-programmatically-ignore-f) ! – AllTooSir Jul 29 '13 at 11:31

2 Answers2

12

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

Oliver
  • 3,815
  • 8
  • 35
  • 63
nutlike
  • 4,835
  • 1
  • 25
  • 33
  • 11
    Or, generally: @JsonIgnoreProperties(ignoreUnknown = true) – Michał Ziober Jul 29 '13 at 12:07
  • @MichałZiober: Since the question states "… I cannot configure the used object mapper to ignore unknown properties." I opted for the specific version, but you are certainly right. – nutlike Jul 29 '13 at 12:25
  • 1
    I know, but I wanted to show another possibility. Your answer is correct and should be used first. – Michał Ziober Jul 29 '13 at 12:31
0

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()

Radouxca
  • 144
  • 1
  • 7