'Object Mapper to implement not null
How to implement below :- fail if name/id/sal isnull or missing/or has null value then string->pojo should fail.How can i implement ? Actual json is nested .I have simplifed the json and class structure for brevity.
MyClass m = objectMapper.readValue(myClassStringValue, MyClass.class); // fail if name/
public class MyClass
{
@JsonProperty("name")
@NotNull
private String name;
@JsonProperty("id")
@NotNull
private String id;
@JsonProperty("sal")
@NotNull
private String sal;
}
Solution 1:[1]
ObjectMapper objectMapper= new ObjectMapper(); objectMapper.configure(DeserializationFeature.FAIL_ON_NULL_CREATOR_PROPERTIES, true);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | JyotiKumarPoddar |
