-
Notifications
You must be signed in to change notification settings - Fork 175
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
See if there is benefit from integrating with jackson-databind better wrt detecting "default" Constructor for Kotlin (data) classes #805
Comments
Makes sense. So we are making (2) pluggable from modules. The approach itself sounds good and all, so I guess the problem lies in whether the introduction of new method could smoothly fit in to the existing functionality, with minimal regression. So the question might be... do we have enough test cases here in Kotlin module? |
@JooHyukKim Exactly, great summary. I am not sure on test coverage, to be honest. |
Yes. Currently, there is a risk that the registration order of |
Right: handling of explicit Creators is improved, and pluggable (yet to be added) Canonical Creator detection (if and only if no explicit ones found) could help both reduce code needed on Module side and make handling work more uniformly. I think there are still some other aspects databind would need to expose, wrt handling of missing values. But it'd be great if there was a way to convert/upgrade things incrementally. |
Now that we all agree, filed FasterXML/jackson-databind#4584 as a start. |
Quick note: FasterXML/jackson-databind#4584 was just implemented in jackson-databind 2.18 branch. |
Changed to implement findDefaultCreator. Fixes FasterXML#805.
@cowtowncoder |
Excellent! It is also possible that handling of standard Jackson annotations for Creators might be improved as well (ability to configure constructor parameters etc, even when not using explicit And just to add a link: looks like #818 was the PR that resolved this issue. |
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:
@JsonCreator
on ctor/factory, or at least one parameter of ctor/factory annotated with@JsonProperty
)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.The text was updated successfully, but these errors were encountered: