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

Mangle constructor parameter names to preserve read-after-write #351

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -153,4 +154,4 @@ internal class KotlinNamesAnnotationIntrospector(val module: KotlinModule, val c
return null
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<NonIdiomaticPascalCasedClass>(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 {
Expand Down