From 4dbc514dbc9a47e2f1ce2b26ab35b7ead12c9e0c Mon Sep 17 00:00:00 2001 From: Tatu Saloranta Date: Fri, 27 Dec 2019 17:53:53 -0800 Subject: [PATCH] Fix #270 /cc @apatrida (sanity check would be appreciated) --- release-notes/VERSION-2.x | 6 ++++++ .../kotlin/KotlinNamesAnnotationIntrospector.kt | 3 ++- .../jackson/module/kotlin/test/github/Github114.kt | 6 ++---- .../jackson/module/kotlin/test/github/Github149.kt | 12 ++++++------ .../kotlin/test/{failing => github}/Github270.kt | 2 +- 5 files changed, 17 insertions(+), 12 deletions(-) rename src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/{failing => github}/Github270.kt (89%) diff --git a/release-notes/VERSION-2.x b/release-notes/VERSION-2.x index a6f33c54..b635bfaf 100644 --- a/release-notes/VERSION-2.x +++ b/release-notes/VERSION-2.x @@ -4,6 +4,12 @@ Project: jackson-module-kotlin === Releases === ------------------------------------------------------------------------ +2.10.2 (not yet released) + +#270: 2.10.1 seems to output JSON field where name of function matches + name of private field + (reported by daviddenton@github) + 2.10.1 (10-Nov-2019) #80: Boolean property name starting with 'is' not serialized/deserialized properly diff --git a/src/main/kotlin/com/fasterxml/jackson/module/kotlin/KotlinNamesAnnotationIntrospector.kt b/src/main/kotlin/com/fasterxml/jackson/module/kotlin/KotlinNamesAnnotationIntrospector.kt index 1c2a4972..594795b3 100644 --- a/src/main/kotlin/com/fasterxml/jackson/module/kotlin/KotlinNamesAnnotationIntrospector.kt +++ b/src/main/kotlin/com/fasterxml/jackson/module/kotlin/KotlinNamesAnnotationIntrospector.kt @@ -33,7 +33,8 @@ internal class KotlinNamesAnnotationIntrospector(val module: KotlinModule, val c // 25-Oct-2019: [module-kotlin#80] Match "isGetter" with field with same name // since Kotlin generates accessor different from Java if (member.declaringClass.isKotlinClass()) { - if (cache.isKotlinGeneratedMethod(member) { it.declaringClass.declaredFields.any { f -> f.name == member.name } }) { + if (cache.isKotlinGeneratedMethod(member) { it.declaringClass.declaredFields.any { + f -> f.name.startsWith("is") && f.name == member.name } }) { return member.name } } diff --git a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github114.kt b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github114.kt index 392faecf..fb8c5536 100644 --- a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github114.kt +++ b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github114.kt @@ -58,7 +58,7 @@ class TestGithub114 { val v = Nada.Companion::foo assertEquals("OK 42", v.callBy(mapOf())) val v2 = FooWithStaticCreator.Companion::createFromJson.javaMethod!!.kotlinFunction!! - println(v2.callBy(mapOf(v2.parameters.first() to FooWithStaticCreator, v2.parameters.drop(1).first() to "asdf"))) +// println(v2.callBy(mapOf(v2.parameters.first() to FooWithStaticCreator, v2.parameters.drop(1).first() to "asdf"))) } private class Nada { @@ -67,6 +67,4 @@ class TestGithub114 { fun foo(x: Int = 42) = "OK $x" } } - - -} \ No newline at end of file +} diff --git a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github149.kt b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github149.kt index 5480a8f4..4c275e29 100644 --- a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github149.kt +++ b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github149.kt @@ -47,14 +47,14 @@ class TestGithub149 { val f1 = Foo("f1", listOf(fAtt)) fAtt.parent = f1 - println(f1) - println("=============") +// println(f1) +// println("=============") val f1AsJson = mapper.writeValueAsString(f1) - println(f1AsJson) - println("=============") +// println(f1AsJson) +// println("=============") val mFromJson = mapper.readValue(f1AsJson, Foo::class.java) - println(mFromJson) +// println(mFromJson) } data class Car( @@ -81,6 +81,6 @@ class TestGithub149 { c.colors.add(color) val s = mapper.writeValueAsString(c) val value = mapper.readValue(s, Car::class.java) - print(value) +// print(value) } } \ No newline at end of file diff --git a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/failing/Github270.kt b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github270.kt similarity index 89% rename from src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/failing/Github270.kt rename to src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github270.kt index 29f65a7e..36e90041 100644 --- a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/failing/Github270.kt +++ b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github270.kt @@ -1,4 +1,4 @@ -package com.fasterxml.jackson.module.kotlin.test.failing +package com.fasterxml.jackson.module.kotlin.test.github import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper import org.junit.Test