Jackson @JsonProperty(required=true) doesn’t throw an exception

With Jackson 2.6 you can use required, however you have to do it using JsonCreator

For example:

public class MyClass {

    @JsonCreator
    public MyClass(@JsonProperty(value = "x", required = true) Integer x, @JsonProperty(value = "value_y", required = true) Integer y) {
        this.x = x;
        this.y = y;
    }

    private Integer x;
    private Integer y;
}

If x or y are not present an exception will be thrown when trying to deserialize it.

Leave a Comment