-
-
Notifications
You must be signed in to change notification settings - Fork 143
Description
With 2.18 jackson-databind has a new, rewritten logic for POJO Property detection: work was done mostly under FasterXML/jackson-databind#4515.
Logic, at high-level, selects at most one "Properties-based" Creator (constructor / static factory method), in following order:
- Explicitly annotated (either
@JsonCreator
on ctor/factory, or at least one parameter of ctor/factory annotated with@JsonProperty
) - Canonical -- currently only detected for Record types
- Implicit Constructor: if all parameters of a constructor have implicit names, is visible (by default: public) and there is only one such choice (not even 0-args "default" constructor)
This works for many cases. But JVM languages like Scala (and Kotlin) typically have their own definition of canonical constructor, so it'd be good to allow pluggable handling.
(in plain Java we only have Records with the concept of specific canonical (primary) constructor, over alternatives that are also visible)
My initial idea would be to add one (ideally) new method in AnnotationIntrospector
, which would take 2 sets of candidates -- Constructors and Factory Methods (PotentialCreator
) -- that might qualify; and result would be zero or one of passed-in choices to indicate Canonical, Properties-based creator to use, if any.
Method would only be called if no explicit choice were found.
I am not sure if similar functionality should be available to allow implicit Delegating Creator: possibly?
If so, it would be given 2 sets of potential candidates, as well as previously chosen Properties-based creator, if any. But I am not yet sure that is needed.
Would the first part make sense, @pjfanning, from Scala module perspective?