-
-
Notifications
You must be signed in to change notification settings - Fork 338
Description
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:
@JsonProperty
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 = truecase 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
OptBooleanvalue - support combination of both new
isRequired(higher precedence) and oldrequired(lower precedence) via databindAnnotationIntrospector - for Jackson 3.0, mark
requiredas 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.