@@ -2,17 +2,20 @@ package com.fasterxml.jackson.module.kotlin.test.github
2
2
3
3
import com.fasterxml.jackson.core.JsonGenerator
4
4
import com.fasterxml.jackson.databind.SerializerProvider
5
+ import com.fasterxml.jackson.databind.annotation.JsonSerialize
5
6
import com.fasterxml.jackson.databind.module.SimpleModule
6
7
import com.fasterxml.jackson.databind.ser.std.StdSerializer
7
8
import com.fasterxml.jackson.module.kotlin.jacksonMapperBuilder
9
+ import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
8
10
import org.junit.Test
9
11
import kotlin.test.assertEquals
12
+ import kotlin.test.assertNotEquals
10
13
11
14
// Most of the current behavior has been tested on GitHub464, so only serializer-related behavior is tested here.
12
15
class GitHub524 {
13
16
@JvmInline
14
17
value class HasSerializer (val value : Int? )
15
- object Serializer : StdSerializer<HasSerializer>(HasSerializer : :class.java) {
18
+ class Serializer : StdSerializer <HasSerializer >(HasSerializer : :class.java) {
16
19
override fun serialize (value : HasSerializer , gen : JsonGenerator , provider : SerializerProvider ) {
17
20
gen.writeString(value.toString())
18
21
}
@@ -35,7 +38,7 @@ class GitHub524 {
35
38
@Test
36
39
fun test () {
37
40
val sm = SimpleModule ()
38
- .addSerializer(Serializer )
41
+ .addSerializer(Serializer () )
39
42
val writer = jacksonMapperBuilder().addModule(sm).build().writerWithDefaultPrettyPrinter()
40
43
41
44
// 18446744073709551615 is ULong.MAX_VALUE.
@@ -52,4 +55,21 @@ class GitHub524 {
52
55
writer.writeValueAsString(Poko ())
53
56
)
54
57
}
58
+
59
+ class SerializeByAnnotation (@get:JsonSerialize(using = Serializer ::class) val foo : HasSerializer = HasSerializer (1))
60
+
61
+ @Test
62
+ fun failing () {
63
+ val writer = jacksonObjectMapper().writerWithDefaultPrettyPrinter()
64
+
65
+ // JsonSerialize is not working now.
66
+ assertNotEquals(
67
+ """
68
+ {
69
+ "foo" : "HasSerializer(value=1)"
70
+ }
71
+ """ .trimIndent(),
72
+ writer.writeValueAsString(SerializeByAnnotation ())
73
+ )
74
+ }
55
75
}
0 commit comments