-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Closed
Milestone
Description
public class Test {
private String type;
private long num;
@JsonCreator
public Test(@JsonProperty(value = "type", required = true) String type,
@JsonProperty(value = "num", required = true) long num) {
this.type = type;
this.num = num;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public long getNum() {
return num;
}
public void setNum(long num) {
this.num = num;
}
}
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.configure(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES, true);
try {
String json = "{ \"type\" : \"number\", \"num\":null }";
Test car = objectMapper.readValue(json, Test.class);
System.out.println(car.getNum());
} catch (MismatchedInputException ex) {
ex.getPath().forEach(it -> System.out.println("field: " + it.getFieldName()));
}
shows field: num
but missing field in json
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.configure(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES, true);
try {
String json = "{ \"type\" : \"number\" }";
Test car = objectMapper.readValue(json, Test.class);
System.out.println(car.getNum());
} catch (MismatchedInputException ex) {
ex.getPath().forEach(it -> System.out.println("field: " + it.getFieldName()));
}
shows nothing
Please add filed name and in this case.
Metadata
Metadata
Assignees
Labels
No labels