When deserializing from json, is there an easy way for ObjectMapper to throw an exception when a required field is missing from json?
Asked
Active
Viewed 6,988 times
3
-
1The `@JsonProperty` annotation does provide such a functionality. See: http://fasterxml.github.io/jackson-annotations/javadoc/2.1.0/com/fasterxml/jackson/annotation/JsonProperty.html#required%28%29 – nif Jul 15 '13 at 18:49
-
1After annotating a field with @JsonProperty(required=true), how can I detect it when this field is missing from json? – Shuo Jul 15 '13 at 19:07
-
It should throw an exception while deserialization. – nif Jul 16 '13 at 08:07
-
I cannot seem to get this work. Do you mind share some basic examples? Thanks. – Shuo Jul 17 '13 at 18:15
-
1It seems JsonProperty is not supported during deserialization. https://github.com/FasterXML/jackson-databind/issues/174 – Shuo Jul 17 '13 at 18:17