FasterXML / FasterXML/jackson-module-scala

See if there is benefit from integrating with jackson-databind better wrt detecting "canonical" Constructor for Scala (case) classes

Aperta
#677 4 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
Scala
Stelle
506
Fork
138
Merge medio
3h 6m
PR unite (30g)
48

Descrizione

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?

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.