From d0f9ab6d956b202654ff64e5a877a659a4b43b1a Mon Sep 17 00:00:00 2001 From: Alex Popiel Date: Thu, 2 Jul 2020 17:25:36 -0700 Subject: [PATCH] Mangle constructor parameter names to preserve read-after-write --- .../kotlin/KotlinNamesAnnotationIntrospector.kt | 5 +++-- .../module/kotlin/test/ParameterNameTests.kt | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) 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 53e2fdde..039bec56 100644 --- a/src/main/kotlin/com/fasterxml/jackson/module/kotlin/KotlinNamesAnnotationIntrospector.kt +++ b/src/main/kotlin/com/fasterxml/jackson/module/kotlin/KotlinNamesAnnotationIntrospector.kt @@ -30,7 +30,8 @@ internal class KotlinNamesAnnotationIntrospector(val module: KotlinModule, val c // since 2.4 override fun findImplicitPropertyName(member: AnnotatedMember): String? { if (member is AnnotatedParameter) { - return findKotlinParameterName(member) + val simpleName = findKotlinParameterName(member) + return if (simpleName == null) null else BeanUtil.stdManglePropertyName(simpleName, 0) } return null } @@ -153,4 +154,4 @@ internal class KotlinNamesAnnotationIntrospector(val module: KotlinModule, val c return null } -} \ No newline at end of file +} diff --git a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/ParameterNameTests.kt b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/ParameterNameTests.kt index 52b15410..6d7837a7 100644 --- a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/ParameterNameTests.kt +++ b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/ParameterNameTests.kt @@ -161,6 +161,20 @@ class TestJacksonWithKotlin { } + // ================== + + private data class NonIdiomaticPascalCasedClass(val Some_Number: Int, val Email_Address: String) + + @Test fun readAfterWriteWithPascalCaseProperties() { + val obj = NonIdiomaticPascalCasedClass(6, "nobody@test.com") + + val serialized = normalCasedMapper.writeValueAsString(obj) + val deserialized = normalCasedMapper.readValue(serialized) + + assertThat(deserialized, equalTo(obj)) + } + + // ================== private class StateObjectWithFactory private constructor (override val name: String, override val age: Int, override val primaryAddress: String, override val wrongName: Boolean, override val createdDt: Date) : TestFields {