One nasty issue with @JsonProperty annotation is that its required property is boolean-valued: and as such cannot indicate "use defaults" / "not defined" option -- and default being false, it means that:
is same as
@JsonProperty(required = false)
so that it is easy to accidentally specify that a property is NOT required. This is especially true when considering cases where there are more generic defaults (provided by modules, f.ex) at, levels like:
- For Constructor (require-all)
- Global defaults (default-unless-overriden)
in which case any use of @JsonProperty either:
- Overrides more general default, OR
- If only
required = true case considered explicit, is impossible to disable "required-ness"
What we need, really, is third state: and use of OptBoolean enum offers that: it has 3 values:
TRUE (-> Boolean.TRUE)
FALSE (-> Boolean.FALSE)
DEFAULT (-> null)
However. We cannot really change type of required property, even with 2.x->3.0 transition -- because we do want to keep jackson-annotations backwards-compatible (in that jackson-annotations 2.x versions will work with 3.x, and (for most purposes) vice-versa).
What we can do is to:
- add new property, "isRequired" with
OptBoolean value
- support combination of both new
isRequired (higher precedence) and old required (lower precedence) via databind AnnotationIntrospector
- for Jackson 3.0, mark
required as Deprecated (... and possibly later 2.x, but not in 2.19)
- Profit!
This issue is for addition of the new property: there will be new jackson-databind ticket for reminder of work.
One nasty issue with
@JsonPropertyannotation is that itsrequiredproperty isboolean-valued: and as such cannot indicate "use defaults" / "not defined" option -- and default beingfalse, it means that:is same as
so that it is easy to accidentally specify that a property is NOT required. This is especially true when considering cases where there are more generic defaults (provided by modules, f.ex) at, levels like:
in which case any use of
@JsonPropertyeither:required = truecase considered explicit, is impossible to disable "required-ness"What we need, really, is third state: and use of
OptBooleanenum offers that: it has 3 values:TRUE(->Boolean.TRUE)FALSE(->Boolean.FALSE)DEFAULT(->null)However. We cannot really change type of
requiredproperty, even with 2.x->3.0 transition -- because we do want to keepjackson-annotationsbackwards-compatible (in thatjackson-annotations2.x versions will work with 3.x, and (for most purposes) vice-versa).What we can do is to:
OptBooleanvalueisRequired(higher precedence) and oldrequired(lower precedence) via databindAnnotationIntrospectorrequiredas Deprecated (... and possibly later 2.x, but not in 2.19)This issue is for addition of the new property: there will be new
jackson-databindticket for reminder of work.