Skip to content

Support new @JsonProperty.isRequired for overridable definition of "required-ness" #5020

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
cowtowncoder opened this issue Mar 12, 2025 · 2 comments
Labels
2.19 Issues planned at 2.19 or later

Comments

@cowtowncoder
Copy link
Member

Describe your Issue

Now that @JsonProperty has "nullable" isRequired property (see FasterXML/jackson-annotations#284), JacksonAnnotationIntrospector needs to support it.

Logic is such that:

  1. if isRequired has value other than OptBoolean.DEFAULT, it is used as THE choice of required-ness
  2. otherwise if required = true, property is required
  3. otherwise (required = false), either
    • Property is NOT required (Jackson 2.x)
    • Property MAY OR MAY NOT BE required wrt annotation (higher-level defaults used)

This logic is specifically meant to allow finer-grain overridability with working defaults: before this change, setting of @JsonProperty.required -- and often, specifically, its default (false) setting was used.

@cowtowncoder cowtowncoder added the to-evaluate Issue that has been received but not yet evaluated label Mar 12, 2025
@cowtowncoder
Copy link
Member Author

^^^ @k163377 I'll get this done today or tomorrow.

@cowtowncoder cowtowncoder added 2.19 Issues planned at 2.19 or later and removed to-evaluate Issue that has been received but not yet evaluated labels Mar 12, 2025
@cowtowncoder
Copy link
Member Author

Ok: implemented now, so @JsonProperty(isRequired = OptBoolean.TRUE) (etc) work.

Noteworthy on defaulting:

  • In both 2.19 and 3.0, isRequired has precedence, used unless has value OptBoolean.DEFAULT (which is default value if property not included)
  • In 2.19, plain required is still considered exactly like before (cannot really change without compatibility problems) -- although we could of course add MapperFeature to change it if we really really want to. I don't think we do?
  • In 3.0, only value of required = true is considered (to mean property IS required) -- required = false is basically ignored, meaning same as isRequired = OptBoolean.DEFAULT.

So @k163377 I think Kotlin module 3.0 can implement better defaulting behavior.

I think there was some issue here too, related... will see if I can find it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.19 Issues planned at 2.19 or later
Projects
None yet
Development

No branches or pull requests

1 participant