Skip to content
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

Fixed overriding findCreatorAnnotation instead of hasCreatorAnnotation #727

Merged
merged 3 commits into from Nov 20, 2023

Conversation

k163377
Copy link
Contributor

@k163377 k163377 commented Nov 19, 2023

SSIA

fixes #200

else
false
override fun findCreatorAnnotation(config: MapperConfig<*>, ann: Annotated): JsonCreator.Mode? {
if (ann !is AnnotatedConstructor || !ann.isKotlinConstructorWithParameters()) return null
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So Kotlin does not add factory methods as creators, just constructors?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the role of this function is to consider the primary constructor as a JsonCreator when there is no function with JsonCreator assigned.
Factory methods are not processed here because they are explicitly granted JsonCreator.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah. Going forward (2.17?) I hope to add a new type of Creator level -- "preferred" (or "default" or something -- which is higher than implicit (auto-detected) but lower than explicit annotation.
The idea is that it would be used as THE Creator if no annotations used, but actual @JsonCreator annotation could be used to override. But the two would not conflict -- unlike the case of 2 annotated constructors, for example, there would be clear precedence (explicit annotation wins). Similarly "regular" auto-detection could find other candidates (from Java side), but modules (Kotlin, Scala) could indicate something that is automatically preferred.
This would also work better for Java Records which have the "canonical constructor" which should be indicated as "preferred" over alternatives.

Copy link
Member

@cowtowncoder cowtowncoder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, overriding new method makes sense.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand much about this TODO comment, but I moved it to KotrinNamesAnnotationIntrospector just in case.

@k163377 k163377 merged commit 0586949 into FasterXML:2.17 Nov 20, 2023
16 checks passed
@k163377 k163377 deleted the find-creator branch November 24, 2023 19:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants