I am mapping my API JSON response to Java object using ObjectMapper (Jackson). Below is how my json looks like :
[
{
firstKey : "value1",
secondKey : "value2",
thirdKey : "value3"
},
{
firstKey : "value4",
secondKey : "value5",
thirdKey : "value6"
}
]
Required fields are : firstKey secondKey thirdKey
Some of my JSON responses might not have all these three required fields, for which I would like Jackson to throw exception while deserializing. How should I let Jackson know about the required fields ? Is there any annotation for it, except JsonProperty(required = true) since this does not works ?
Also, if a key has null value, it is accepted default value, so I cannot use @NotNull as well. For eg : [ { firstKey : null, secondKey : "value2", thirKey : "value3" } ] Above is valid JSON and should parsed without any exception during deserialization.