Skip to content

Commit cc2a337

Browse files
committed
add tests
1 parent 9cd05ee commit cc2a337

File tree

1 file changed

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

1 file changed

+83
-0
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
package com.fasterxml.jackson.module.kotlin.test.github
2+
3+
import com.fasterxml.jackson.annotation.JsonValue
4+
import com.fasterxml.jackson.module.kotlin.jacksonMapperBuilder
5+
import org.junit.Test
6+
import kotlin.test.assertEquals
7+
8+
class GitHub530 {
9+
// At the moment, the output is the same with or without `JsonValue`,
10+
// but this pattern is included in the test case in case the option to default to a serialization method that
11+
// does not `unbox` is introduced in the future.
12+
@JvmInline value class Foo(@get:JsonValue val value: Int)
13+
@JvmInline value class Bar(@JvmField @field:JsonValue val value: Int)
14+
15+
@JvmInline value class Baz(val value: Int) {
16+
@get:JsonValue val jsonValue: String get() = this.toString()
17+
}
18+
@JvmInline value class Qux(val value: Int) {
19+
@JsonValue fun getJsonValue(): String = this.toString()
20+
}
21+
22+
interface JsonValueGetter { @get:JsonValue val jsonValue: String get() = this.toString() }
23+
@JvmInline value class Quux(val value: Int): JsonValueGetter
24+
@JvmInline value class Corge(val value: Int): JsonValueGetter
25+
26+
@JvmInline value class Grault(val value: Int) {
27+
@get:JsonValue val jsonValue: String get() = this.toString()
28+
}
29+
30+
data class Data<T : Any>(
31+
val foo1: Foo,
32+
val foo2: Foo?,
33+
val bar1: Bar,
34+
val bar2: Bar?,
35+
val baz1: Baz,
36+
val baz2: Baz?,
37+
val qux1: Qux,
38+
val qux2: Qux?,
39+
val quux1: Quux,
40+
val quux2: Quux?,
41+
val corge1: JsonValueGetter,
42+
val corge2: JsonValueGetter?,
43+
val grault1: T,
44+
val grault2: T?
45+
)
46+
47+
@Test
48+
fun test() {
49+
val writer = jacksonMapperBuilder().build().writerWithDefaultPrettyPrinter()
50+
51+
assertEquals(
52+
"""
53+
{
54+
"foo1" : 0,
55+
"foo2" : 1,
56+
"bar1" : 2,
57+
"bar2" : 3,
58+
"baz1" : "Baz(value=4)",
59+
"baz2" : "Baz(value=5)",
60+
"qux1" : "Qux(value=6)",
61+
"qux2" : "Qux(value=7)",
62+
"quux1" : "Quux(value=8)",
63+
"quux2" : "Quux(value=9)",
64+
"corge1" : "Corge(value=10)",
65+
"corge2" : "Corge(value=11)",
66+
"grault1" : "Grault(value=12)",
67+
"grault2" : "Grault(value=13)",
68+
}
69+
""".trimIndent(),
70+
writer.writeValueAsString(
71+
Data(
72+
Foo(0), Foo(1),
73+
Bar(2), Bar(3),
74+
Baz(4), Baz(5),
75+
Qux(6), Qux(7),
76+
Quux(8), Quux(9),
77+
Corge(10), Corge(11),
78+
Grault(12), Grault(13)
79+
)
80+
)
81+
)
82+
}
83+
}

0 commit comments

Comments
 (0)