-
-
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
Fixed overriding findCreatorAnnotation instead of hasCreatorAnnotation #727
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ package com.fasterxml.jackson.module.kotlin | |
|
||
import com.fasterxml.jackson.annotation.JsonCreator | ||
import com.fasterxml.jackson.annotation.JsonProperty | ||
import com.fasterxml.jackson.databind.cfg.MapperConfig | ||
import com.fasterxml.jackson.databind.introspect.Annotated | ||
import com.fasterxml.jackson.databind.introspect.AnnotatedConstructor | ||
import com.fasterxml.jackson.databind.introspect.AnnotatedMember | ||
|
@@ -111,11 +112,15 @@ internal class KotlinNamesAnnotationIntrospector( | |
} | ||
} | ||
|
||
override fun hasCreatorAnnotation(member: Annotated): Boolean = | ||
if (member is AnnotatedConstructor && member.isKotlinConstructorWithParameters()) | ||
cache.checkConstructorIsCreatorAnnotated(member) { hasCreatorAnnotation(it) } | ||
else | ||
false | ||
// TODO: possible work around for JsonValue class that requires the class constructor to have the JsonCreator(DELEGATED) set? | ||
// since we infer the creator at times for these methods, the wrong mode could be implied. | ||
override fun findCreatorAnnotation(config: MapperConfig<*>, ann: Annotated): JsonCreator.Mode? { | ||
if (ann !is AnnotatedConstructor || !ann.isKotlinConstructorWithParameters()) return null | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So Kotlin does not add factory methods as creators, just constructors? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
|
||
return JsonCreator.Mode.DEFAULT.takeIf { | ||
cache.checkConstructorIsCreatorAnnotated(ann) { hasCreatorAnnotation(it) } | ||
} | ||
} | ||
|
||
@Suppress("UNCHECKED_CAST") | ||
private fun findKotlinParameterName(param: AnnotatedParameter): String? { | ||
|
There was a problem hiding this comment.
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 toKotrinNamesAnnotationIntrospector
just in case.