Skip to content

Commit c6549fe

Browse files
committed
1 parent 19d5d3d commit c6549fe

File tree

4 files changed

+176
-0
lines changed

4 files changed

+176
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package io.github.projectmapk.jackson.module.kogera.zPorted.test.github
2+
3+
import com.fasterxml.jackson.core.JsonGenerator
4+
import com.fasterxml.jackson.databind.SerializerProvider
5+
import com.fasterxml.jackson.databind.annotation.JsonSerialize
6+
import com.fasterxml.jackson.databind.ser.std.StdSerializer
7+
import io.github.projectmapk.jackson.module.kogera.jacksonObjectMapper
8+
import org.junit.jupiter.api.Assertions.assertEquals
9+
import org.junit.jupiter.api.Test
10+
11+
class GitHub618 {
12+
@JsonSerialize(using = V.Serializer::class)
13+
@JvmInline
14+
value class V(val value: String) {
15+
class Serializer : StdSerializer<V>(V::class.java) {
16+
override fun serialize(p0: V, p1: JsonGenerator, p2: SerializerProvider) {
17+
p1.writeString(p0.toString())
18+
}
19+
}
20+
}
21+
22+
data class D(val v: V?)
23+
24+
@Test
25+
fun test() {
26+
val mapper = jacksonObjectMapper()
27+
// expected: {"v":null}, but NullPointerException thrown
28+
assertEquals("""{"v":null}""", mapper.writeValueAsString(D(null)))
29+
}
30+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package io.github.projectmapk.jackson.module.kogera.zPorted.test.github
2+
3+
import com.fasterxml.jackson.annotation.JsonInclude
4+
import io.github.projectmapk.jackson.module.kogera.jacksonObjectMapper
5+
import org.junit.jupiter.api.Assertions.assertEquals
6+
import org.junit.jupiter.api.Assertions.assertNotEquals
7+
import org.junit.jupiter.api.Test
8+
9+
class GitHub625 {
10+
@JvmInline
11+
value class Primitive(val v: Int)
12+
13+
@JvmInline
14+
value class NonNullObject(val v: String)
15+
16+
@JvmInline
17+
value class NullableObject(val v: String?)
18+
19+
@JsonInclude(value = JsonInclude.Include.NON_NULL, content = JsonInclude.Include.NON_NULL)
20+
data class Dto(
21+
val primitive: Primitive? = null,
22+
val nonNullObject: NonNullObject? = null,
23+
val nullableObject: NullableObject? = null
24+
) {
25+
fun getPrimitiveGetter(): Primitive? = null
26+
fun getNonNullObjectGetter(): NonNullObject? = null
27+
fun getNullableObjectGetter(): NullableObject? = null
28+
}
29+
30+
@Test
31+
fun test() {
32+
val mapper = jacksonObjectMapper()
33+
val dto = Dto()
34+
assertEquals("{}", mapper.writeValueAsString(dto))
35+
}
36+
37+
@JsonInclude(value = JsonInclude.Include.NON_EMPTY, content = JsonInclude.Include.NON_NULL)
38+
data class FailingDto(
39+
val nullableObject1: NullableObject = NullableObject(null),
40+
val nullableObject2: NullableObject? = NullableObject(null),
41+
val map: Map<Any, Any?> = mapOf("nullableObject" to NullableObject(null),)
42+
) {
43+
fun getNullableObjectGetter1(): NullableObject = NullableObject(null)
44+
fun getNullableObjectGetter2(): NullableObject? = NullableObject(null)
45+
fun getMapGetter(): Map<Any, Any?> = mapOf("nullableObject" to NullableObject(null))
46+
}
47+
48+
@Test
49+
fun failing() {
50+
val writer = jacksonObjectMapper()
51+
val json = writer.writeValueAsString(FailingDto())
52+
53+
assertNotEquals("{}", json)
54+
}
55+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package io.github.projectmapk.jackson.module.kogera.zPorted.test.github
2+
3+
import com.fasterxml.jackson.annotation.JsonKey
4+
import io.github.projectmapk.jackson.module.kogera.jacksonMapperBuilder
5+
import io.github.projectmapk.jackson.module.kogera.testPrettyWriter
6+
import org.junit.jupiter.api.Assertions.assertEquals
7+
import org.junit.jupiter.api.Test
8+
9+
class Github536 {
10+
@JvmInline
11+
value class JsonKeyGetter(val value: Int) {
12+
@get:JsonKey
13+
val jsonKey: String
14+
get() = this.toString()
15+
}
16+
17+
interface IJsonKeyGetter {
18+
@get:JsonKey
19+
val jsonKey: String
20+
get() = this.toString()
21+
}
22+
23+
@JvmInline
24+
value class JsonKeyGetterImplementation(val value: Int) : IJsonKeyGetter
25+
26+
@JvmInline
27+
value class JsonKeyGetterImplementationDisabled(val value: Int) : IJsonKeyGetter {
28+
@get:JsonKey(false)
29+
override val jsonKey: String
30+
get() = super.jsonKey
31+
}
32+
33+
private val writer = jacksonMapperBuilder().build().testPrettyWriter()
34+
35+
@Test
36+
fun test() {
37+
val src = mapOf(
38+
JsonKeyGetter(0) to 0,
39+
JsonKeyGetterImplementation(1) to 1,
40+
JsonKeyGetterImplementationDisabled(2) to 2
41+
)
42+
43+
assertEquals(
44+
"""
45+
{
46+
"JsonKeyGetter(value=0)" : 0,
47+
"JsonKeyGetterImplementation(value=1)" : 1,
48+
"2" : 2
49+
}
50+
""".trimIndent(),
51+
writer.writeValueAsString(src)
52+
)
53+
}
54+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package io.github.projectmapk.jackson.module.kogera.zPorted.test.github
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty
4+
import io.github.projectmapk.jackson.module.kogera.jacksonObjectMapper
5+
import org.junit.jupiter.api.Assertions.assertEquals
6+
import org.junit.jupiter.api.Test
7+
8+
class Github630 {
9+
private val mapper = jacksonObjectMapper()
10+
11+
data class Dto(
12+
// from #570, #603
13+
val FOO: Int = 0,
14+
val bAr: Int = 0,
15+
@JsonProperty("b")
16+
val BAZ: Int = 0,
17+
@JsonProperty("q")
18+
val qUx: Int = 0,
19+
// from #71
20+
internal val quux: Int = 0,
21+
// from #434
22+
val `corge-corge`: Int = 0,
23+
// additional
24+
@get:JvmName("aaa")
25+
val grault: Int = 0
26+
)
27+
28+
@Test
29+
fun test() {
30+
val dto = Dto()
31+
32+
assertEquals(
33+
"""{"FOO":0,"bAr":0,"b":0,"q":0,"quux":0,"corge-corge":0,"grault":0}""",
34+
mapper.writeValueAsString(dto)
35+
)
36+
}
37+
}

0 commit comments

Comments
 (0)