Skip to content

FAIL_ON_NULL_FOR_PRIMITIVES failure does not indicate field name in exception message #2101

@raderio

Description

@raderio
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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions