Created
July 22, 2021 14:36
-
-
Save dinomite/de003f141f359a2028f4cb61c1241ad8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.fasterxml.jackson.module.kotlin.test.github.failing | |
import com.fasterxml.jackson.databind.type.TypeFactory | |
import com.fasterxml.jackson.module.kotlin.KotlinModule | |
import com.fasterxml.jackson.module.kotlin.jacksonTypeRef | |
import com.fasterxml.jackson.module.kotlin.jsonMapper | |
import com.fasterxml.jackson.module.kotlin.readValue | |
import org.junit.Test | |
import kotlin.test.assertEquals | |
class GitHub479Test { | |
val mapper = jsonMapper { | |
this.addModule(KotlinModule(strictNullChecks = true)) | |
} | |
val tf: TypeFactory = mapper.typeFactory | |
val json = "[1, 2, 3, null]" | |
@Test | |
fun fullObject() { | |
class Data(val list: List<Int>) | |
// Throws exception | |
assertEquals( | |
Data(listOf(1, 0)), | |
mapper.readValue("""{"list": [1, null]}""") | |
) | |
} | |
@Test | |
fun readValueInline() { | |
assertEquals( | |
listOf(1, 2, 3, 0), | |
mapper.readValue(json) | |
) | |
} | |
@Test | |
fun readValueLiteral() { | |
assertEquals( | |
listOf(1, 2, 3, 0), | |
mapper.readValue(json, jacksonTypeRef()) | |
) | |
} | |
@Test | |
fun typeFactoryCollectionLikeTypeRef() { | |
assertEquals( | |
listOf(1, 2, 3, 0), | |
mapper.readValue( | |
json, | |
tf.constructCollectionLikeType(List::class.java, tf.constructType(jacksonTypeRef<Int>())) | |
) | |
) | |
} | |
@Test | |
fun typeFactoryCollectionLikeJavaType() { | |
assertEquals( | |
listOf(1, 2, 3, 0), | |
mapper.readValue( | |
json, | |
tf.constructCollectionLikeType(List::class.java, Int::class.java) | |
) | |
) | |
} | |
@Test | |
fun typeFactoryCollectionTypeRef() { | |
assertEquals( | |
listOf(1, 2, 3, 0), | |
mapper.readValue( | |
json, | |
tf.constructCollectionType(List::class.java, tf.constructType(jacksonTypeRef<Int>())) | |
) | |
) | |
} | |
@Test | |
fun typeFactoryCollectionJavaType() { | |
assertEquals( | |
listOf(1, 2, 3, 0), | |
mapper.readValue(json, tf.constructCollectionType(List::class.java, Int::class.java)) | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment