FasterXML / FasterXML/jackson-module-kotlin
Reified types are not inlined into type references of generic classes
- Dominant language
- Kotlin
- Stars
- 1.2k
- Forks
- 187
- Avg merge
- 9h 48m
- Merged PRs (30d)
- 16
Description
When you create a type reference for a generic class with a reified type parameter, this type parameter is still generic, not the inlined type. That prevents deserialization of properties of the reified type.
It might look like very rare case unless you prefer composition over inheritance.
Looks like a new typeOf Kotlin function works correctly in this case. Can we use it somehow?
Kotlin version: 1.3.41
Jackson version: 2.9.9
```Kotlin
val objectMapper = jacksonObjectMapper()
fun main() {
val json = """{ "wrapped": { "content": 42 } }"""
println("objectMapper.readValue>(json): ${objectMapper.readValue>(json)}")
println("jacksonTypeRef>(): ${jacksonTypeRef>().type}")
val readWrapped = readWrapped(json)
println("readWrapped(json): $readWrapped")
println("readWrapped(json).wrapped::class: ${readWrapped.wrapped::class}")
}
@UseExperimental(ExperimentalStdlibApi::class)
private inline fun readWrapped(json: String): Wrap {
println("jacksonTypeRef().type: ${jacksonTypeRef().type}")
println("jacksonTypeRef>().type: ${jacksonTypeRef>().type}")
println("typeOf>(): ${typeOf>()}")
return objectMapper.readValue(json)
}
data class Wrap(val wrapped: V)
data class Box(val content: Int)
```
Output:
```
objectMapper.readValue>(json): Wrap(wrapped=Box(content=42))
jacksonTypeRef>(): Wrap
jacksonTypeRef().type: class Box
jacksonTypeRef>().type: Wrap
typeOf>(): Wrap
readWrapped(json): Wrap(wrapped={content=42})
readWrapped(json).wrapped::class: class java.util.LinkedHashMap
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.