FasterXML / FasterXML/jackson-module-scala
See if there is benefit from integrating with jackson-databind better wrt detecting "canonical" Constructor for Scala (case) classes
- Vorherrschende Sprache
- Scala
- Sterne
- 506
- Forks
- 138
- Ø Merge
- 3 Std. 6 Min.
- Gemergte PRs (30 T.)
- 48
Beschreibung
With 2.18 jackson-databind has a new, rewritten logic for POJO Property detection: work was done mostly under https://github.com/FasterXML/jackson-databind/issues/4515.
Logic, at high-level, selects at most one "Properties-based" Creator (constructor / static factory method), in following order:
1. Explicitly annotated (either `@JsonCreator` on ctor/factory, or at least one parameter of ctor/factory annotated with `@JsonProperty`)
2. Canonical -- currently only detected for Record types
3. 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?
Beitragsleitfaden
Für dieses Repository ist kein Beitragsleitfaden indexiert
Bewertung
Dieses Issue wurde noch nicht bewertet.