Skip to content

Commit

Permalink
Merge pull request #904 from k163377/fix-873
Browse files Browse the repository at this point in the history
Fixed an error when serializing a `value class` that wraps a `Map`
  • Loading branch information
k163377 authored Feb 2, 2025
2 parents 3f117c3 + 73c49da commit e30c612
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 1 deletion.
1 change: 1 addition & 0 deletions release-notes/CREDITS-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ object ValueClassUnboxSerializer : StdSerializer<Any>(Any::class.java) {
return
}

provider.findValueSerializer(unboxed::class.java).serialize(unboxed, gen, provider)
provider.defaultSerializeValue(unboxed, gen)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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<TimestampedPerson>(serialized)

assert(
deserialized == TimestampedPerson(
123L,
Person(person.properties),
)
)
}

@JvmInline
value class Person(
val properties: Map<String, Any>,
)

data class TimestampedPerson(
val timestamp: Long,
val person: Person,
)
}

0 comments on commit e30c612

Please sign in to comment.