From f6479ca8039d82277cde90070418bf37310fce55 Mon Sep 17 00:00:00 2001 From: wrongwrong Date: Sun, 2 Feb 2025 12:46:34 +0900 Subject: [PATCH 1/3] Add test for #873 --- .../module/kotlin/test/github/GitHub873.kt | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/GitHub873.kt diff --git a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/GitHub873.kt b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/GitHub873.kt new file mode 100644 index 000000000..dfe236440 --- /dev/null +++ b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/GitHub873.kt @@ -0,0 +1,46 @@ +package com.fasterxml.jackson.module.kotlin.test.github + +import com.fasterxml.jackson.module.kotlin.defaultMapper +import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper +import com.fasterxml.jackson.module.kotlin.readValue +import kotlin.test.Test + +class GitHub873 { + @Test + fun `should serialize value class`() { + + val person = Person( + mapOf( + "id" to "123", + "updated" to "2023-11-22 12:11:23", + "login" to "2024-01-15", + ), + ) + + val serialized = defaultMapper.writeValueAsString( + TimestampedPerson( + 123L, + Person(person.properties), + ) + ) + + val deserialized = defaultMapper.readValue(serialized) + + assert( + deserialized == TimestampedPerson( + 123L, + Person(person.properties), + ) + ) + } + + @JvmInline + value class Person( + val properties: Map, + ) + + data class TimestampedPerson( + val timestamp: Long, + val person: Person, + ) +} From 04cbf7dcda74556c506b9652e38d746687843385 Mon Sep 17 00:00:00 2001 From: wrongwrong Date: Sun, 2 Feb 2025 12:53:43 +0900 Subject: [PATCH 2/3] Fixed serialization method fixes #873 --- .../com/fasterxml/jackson/module/kotlin/KotlinSerializers.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/com/fasterxml/jackson/module/kotlin/KotlinSerializers.kt b/src/main/kotlin/com/fasterxml/jackson/module/kotlin/KotlinSerializers.kt index 81e841460..efffdd6a2 100644 --- a/src/main/kotlin/com/fasterxml/jackson/module/kotlin/KotlinSerializers.kt +++ b/src/main/kotlin/com/fasterxml/jackson/module/kotlin/KotlinSerializers.kt @@ -62,7 +62,7 @@ object ValueClassUnboxSerializer : StdSerializer(Any::class.java) { return } - provider.findValueSerializer(unboxed::class.java).serialize(unboxed, gen, provider) + provider.defaultSerializeValue(unboxed, gen) } } From 73c49dafa25c1ceed81bfa266dbd930be7a3eb20 Mon Sep 17 00:00:00 2001 From: wrongwrong Date: Sun, 2 Feb 2025 13:00:48 +0900 Subject: [PATCH 3/3] Update release notes wrt #904 --- release-notes/CREDITS-2.x | 1 + release-notes/VERSION-2.x | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/release-notes/CREDITS-2.x b/release-notes/CREDITS-2.x index 596e12d42..2da904ac5 100644 --- a/release-notes/CREDITS-2.x +++ b/release-notes/CREDITS-2.x @@ -18,6 +18,7 @@ Contributors: # 2.18.3 (not yet released) WrongWrong (@k163377) +* #904: Fixed an error when serializing a `value class` that wraps a `Map` * #900: Fixed an issue where some tests were not running # 2.18.0 (26-Sep-2024) diff --git a/release-notes/VERSION-2.x b/release-notes/VERSION-2.x index ccf7af5c4..4f3a68d98 100644 --- a/release-notes/VERSION-2.x +++ b/release-notes/VERSION-2.x @@ -16,6 +16,10 @@ Co-maintainers: === Releases === ------------------------------------------------------------------------ +2.18.3 (not yet released) + +#904: An error that occurred when serializing a `value class` that wraps a `Map`(#873) has been fixed. + 2.18.2 (27-Nov-2024) 2.18.1 (28-Oct-2024)