Skip to content

Content null handling not working for root values #3227

@joca-bt

Description

@joca-bt

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions