Skip to content

Enforce @JsonProperty.required when using builder.Β #2618

Open
@edinardo

Description

@edinardo

When using @JsonProperty(required = true) with creator/factory (@JsonCreator annotation), an exception is raised if a required field is missing (as expected).

It is possible to have the same feature when using a builder to deserialize?

Sorry if this request is duplicate or already present, but I couldn't find it at issues list, forum, neither as configuration on the ObjectMapper documentation.

Tested with Jackson version 2.10.2, using the following code:

@JsonDeserialize(builder = Person.Builder.class)
public class Person {
    @JsonProperty(required = true)
    private final String name;
    ...
    public static class Builder {
        public Builder withName(String value) {...}
        public Person build() {...}
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    builder-relatedIssue related to handling of Builder-style deserialization

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions