-
-
Notifications
You must be signed in to change notification settings - Fork 181
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
) - Default/preferred/primary -- currently only detected for Record types (canonical constructor)
- 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)
Oh these steps, (2) is basically new category added, to better support "no-annotations" use case but with reliable detection and mode selection.
This works for many cases. But JVM languages like Scala (and Kotlin) typically have their own definitions of a default 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 Default/preferred, Properties-based creator to use, if any.
Method would only be called (or its return value used) if no explicit choice were found.
Would this make sense from Kotlin module perspective @k163377 @JooHyukKim ?
My intent is specifically to allow code in module to get simpler, get better out-of-the-box support for core Jackson annotations, and not to complicate things.
EDIT: now databind issue #4584 has been implemented, adding AnnotationIntrospector.findDefaultCreator(...)
which would be the mechanism.