-
-
Notifications
You must be signed in to change notification settings - Fork 175
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #904 from k163377/fix-873
Fixed an error when serializing a `value class` that wraps a `Map`
- Loading branch information
Showing
4 changed files
with
52 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/GitHub873.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) | ||
} |