-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Closed
Milestone
Description
I am trying to build an ObjectMapper which doesn't allow nulls. I noticed some slight discrepancy in behaviour depending on whether I am deserializing to a custom class representing a JSON object or something else.
public class Input {
public Boolean field;
}
ObjectMapper objectMapper = JsonMapper.builder()
.defaultSetterInfo(JsonSetter.Value.construct(Nulls.FAIL, Nulls.FAIL))
.build();
objectMapper.readValue("null", Boolean.class); // 1) returns null
objectMapper.readValue("null", boolean.class); // 2) returns null
objectMapper.readValue("{ \"field\": null }", Map.class); // 3) returns Map.of("field", null)
objectMapper.readValue("{ \"field\": null }", Input.class); // 4) throws error
I was trying to generate an error for all cases but only getting for 4). Is this expected?
Metadata
Metadata
Assignees
Labels
No labels