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