Skip to content

Commit 2de548a

Browse files
committed
add test
1 parent 19c5c02 commit 2de548a

File tree

1 file changed

+55
-0
lines changed
  • src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github

1 file changed

+55
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package com.fasterxml.jackson.module.kotlin.test.github
2+
3+
import com.fasterxml.jackson.core.JsonGenerator
4+
import com.fasterxml.jackson.databind.SerializerProvider
5+
import com.fasterxml.jackson.databind.module.SimpleModule
6+
import com.fasterxml.jackson.databind.ser.std.StdSerializer
7+
import com.fasterxml.jackson.module.kotlin.jacksonMapperBuilder
8+
import org.junit.Test
9+
import kotlin.test.assertEquals
10+
11+
// Most of the current behavior has been tested on GitHub464, so only serializer-related behavior is tested here.
12+
class GitHub524 {
13+
@JvmInline
14+
value class HasSerializer(val value: Int?)
15+
object Serializer : StdSerializer<HasSerializer>(HasSerializer::class.java) {
16+
override fun serialize(value: HasSerializer, gen: JsonGenerator, provider: SerializerProvider) {
17+
gen.writeString(value.toString())
18+
}
19+
}
20+
21+
@JvmInline
22+
value class NoSerializer(val value: Int?)
23+
24+
data class Poko(
25+
// ULong has a custom serializer defined in Serializers.
26+
val foo: ULong = ULong.MAX_VALUE,
27+
// If a custom serializer is set, the ValueClassUnboxSerializer will be overridden.
28+
val bar: HasSerializer = HasSerializer(1),
29+
val baz: HasSerializer = HasSerializer(null),
30+
val qux: HasSerializer? = null,
31+
// If there is no serializer, it will be unboxed as the existing.
32+
val quux: NoSerializer = NoSerializer(2)
33+
)
34+
35+
@Test
36+
fun test() {
37+
val sm = SimpleModule()
38+
.addSerializer(Serializer)
39+
val writer = jacksonMapperBuilder().addModule(sm).build().writerWithDefaultPrettyPrinter()
40+
41+
// 18446744073709551615 is ULong.MAX_VALUE.
42+
assertEquals(
43+
"""
44+
{
45+
"foo" : 18446744073709551615,
46+
"bar" : "HasSerializer(value=1)",
47+
"baz" : "HasSerializer(value=null)",
48+
"qux" : null,
49+
"quux" : 2
50+
}
51+
""".trimIndent(),
52+
writer.writeValueAsString(Poko())
53+
)
54+
}
55+
}

0 commit comments

Comments
 (0)