Skip to content

Commit

Permalink
Issue FasterXML#356 Demangling kotlin getter
Browse files Browse the repository at this point in the history
  • Loading branch information
elektro-wolle committed Oct 12, 2020
1 parent 4b90781 commit daba3a9
Showing 1 changed file with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.fasterxml.jackson.databind.introspect.Annotated
import com.fasterxml.jackson.databind.introspect.AnnotatedConstructor
import com.fasterxml.jackson.databind.introspect.AnnotatedField
import com.fasterxml.jackson.databind.introspect.AnnotatedMember
import com.fasterxml.jackson.databind.introspect.AnnotatedMethod
import com.fasterxml.jackson.databind.introspect.AnnotatedParameter
import com.fasterxml.jackson.databind.introspect.NopAnnotationIntrospector
import com.fasterxml.jackson.databind.util.BeanUtil
Expand All @@ -25,12 +26,24 @@ import kotlin.reflect.jvm.javaType
import kotlin.reflect.jvm.kotlinFunction

internal class KotlinNamesAnnotationIntrospector(val module: KotlinModule, val cache: ReflectionCache, val ignoredClassesForImplyingJsonCreator: Set<KClass<*>>) : NopAnnotationIntrospector() {
/*
override public fun findNameForDeserialization(annotated: Annotated?): PropertyName? {
// This should not do introspection here, only for explicit naming by annotations

/**
* resolve the name of the property, if not given otherwise.
*/
override fun findNameForSerialization(a: Annotated?): PropertyName? {
if (a is AnnotatedMethod) {
if (a.name.startsWith("get") &&

This comment has been minimized.

Copy link
@efenderbosch

efenderbosch Oct 12, 2020

Might want to add:

a.declaringClass.methods.any { it.name == "box-impl" }

to ensure that this is an inline class. Or declaredMethods. I always forget which is which.

a.name.contains('-') &&
a.parameterCount == 0) {
return PropertyName(a.name.substringAfter("get").decapitalize().substringBefore('-'))
} else if (a.name.startsWith("is") &&
a.name.contains('-') &&
a.parameterCount == 0) {
return PropertyName(a.name.substringAfter("is").decapitalize().substringBefore('-'))
}
}
return null
}
*/

// since 2.4
override fun findImplicitPropertyName(member: AnnotatedMember): String? {
Expand Down

0 comments on commit daba3a9

Please sign in to comment.