File tree 4 files changed +29
-17
lines changed
main/kotlin/com/fasterxml/jackson/module/kotlin
test/kotlin/com/fasterxml/jackson/module/kotlin/test/github
4 files changed +29
-17
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ Contributors:
18
18
# 2 .18.3 (not yet released)
19
19
20
20
WrongWrong (@k163377 )
21
+ * #908 : Additional fixes related to #904.
21
22
* #904 : Fixed an error when serializing a `value class` that wraps a `Map`
22
23
* #900 : Fixed an issue where some tests were not running
23
24
Original file line number Diff line number Diff line change @@ -18,7 +18,9 @@ Co-maintainers:
18
18
19
19
2.18 .3 (not yet released )
20
20
21
- #904 : An error that occurred when serializing a `value class ` that wraps a `Map `(#873 ) has been fixed.
21
+ #904 : Fixed a problem where context was not being propagated properly when serializing an unboxed value of `value class `
22
+ or a value retrieved with `JsonValue `.
23
+ This fixes a problem where an error would occur when serializing a `value class ` that wraps a `Map `(#873 ).
22
24
23
25
2.18 .2 (27 - Nov - 2024 )
24
26
2.18 .1 (28 - Oct - 2024 )
Original file line number Diff line number Diff line change @@ -56,12 +56,6 @@ object ValueClassUnboxSerializer : StdSerializer<Any>(Any::class.java) {
56
56
57
57
override fun serialize (value : Any , gen : JsonGenerator , provider : SerializerProvider ) {
58
58
val unboxed = value::class .java.getMethod(" unbox-impl" ).invoke(value)
59
-
60
- if (unboxed == null ) {
61
- provider.findNullValueSerializer(null ).serialize(null , gen, provider)
62
- return
63
- }
64
-
65
59
provider.defaultSerializeValue(unboxed, gen)
66
60
}
67
61
}
@@ -76,9 +70,7 @@ internal sealed class ValueClassSerializer<T : Any>(t: Class<T>) : StdSerializer
76
70
val unboxed = unboxMethod.invoke(value)
77
71
// As shown in the processing of the factory function, jsonValueGetter is always a static method.
78
72
val jsonValue: Any? = staticJsonValueGetter.invoke(null , unboxed)
79
- jsonValue
80
- ?.let { provider.findValueSerializer(it::class .java).serialize(it, gen, provider) }
81
- ? : provider.findNullValueSerializer(null ).serialize(null , gen, provider)
73
+ provider.defaultSerializeValue(jsonValue, gen)
82
74
}
83
75
}
84
76
Original file line number Diff line number Diff line change 1
1
package com.fasterxml.jackson.module.kotlin.test.github
2
2
3
+ import com.fasterxml.jackson.annotation.JsonValue
3
4
import com.fasterxml.jackson.module.kotlin.defaultMapper
4
5
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
5
6
import com.fasterxml.jackson.module.kotlin.readValue
6
7
import kotlin.test.Test
7
8
8
9
class GitHub873 {
10
+ @JvmInline
11
+ value class Person (
12
+ val properties : Map <String , Any >,
13
+ )
14
+
15
+ data class TimestampedPerson (
16
+ val timestamp : Long ,
17
+ val person : Person ,
18
+ )
19
+
9
20
@Test
10
21
fun `should serialize value class` () {
11
22
@@ -35,12 +46,18 @@ class GitHub873 {
35
46
}
36
47
37
48
@JvmInline
38
- value class Person (
39
- val properties : Map <String , Any >,
40
- )
49
+ value class MapAsJsonValue (val value : String ) {
50
+ @get:JsonValue
51
+ val jsonValue get() = mapOf (" key" to value)
52
+ }
41
53
42
- data class TimestampedPerson (
43
- val timestamp : Long ,
44
- val person : Person ,
45
- )
54
+ data class JsonValueWrapper (val value : MapAsJsonValue )
55
+
56
+ @Test
57
+ fun `JsonValue is serialized in the same way` () {
58
+ val data = JsonValueWrapper (MapAsJsonValue (" value" ))
59
+ val json = defaultMapper.writeValueAsString(data)
60
+
61
+ assert (""" {"value":{"key":"value"}}""" == json)
62
+ }
46
63
}
You can’t perform that action at this time.
0 commit comments