Here is my codes :
```kotlin
@JsonTypeInfo(
use = JsonTypeInfo.Id.CUSTOM,
property = "type",
include = JsonTypeInfo.As.PROPERTY,
visible = true
)
@JsonNaming(SnakeCaseStrategy::class)
@JsonTypeIdResolver(BaseTypeIdResolver::class)
interface Base
private object BaseTypeIdResolver : TypeIdResolver {
override fun init(baseType: JavaType?) {
// do nothing
}
override fun idFromValue(value: Any): String {
return idFromValueAndType(value, value.javaClass)
}
override fun idFromValueAndType(value: Any, suggestedType: Class<*>): String = when (value) {
is Sub -> "sub"
else -> throw IllegalArgumentException()
}
override fun idFromBaseType(): String {
throw UnsupportedOperationException()
}
override fun typeFromId(context: DatabindContext, id: String): JavaType {
return when (id) {
"sub" -> context.constructType(Sub::class.java)!!
else -> throw IllegalArgumentException()
}
}
override fun getDescForKnownTypeIds(): String? {
return null
}
override fun getMechanism(): JsonTypeInfo.Id {
return JsonTypeInfo.Id.CUSTOM
}
}
@JsonTypeInfo(
use = JsonTypeInfo.Id.CUSTOM,
property = "sub_type",
include = JsonTypeInfo.As.PROPERTY,
visible = true
)
@JsonTypeIdResolver(SubTypeIdResolver::class)
interface Sub : Base
object SubTypeIdResolver : TypeIdResolver {
override fun init(baseType: JavaType?) {
// do nothing
}
override fun idFromValue(value: Any): String {
return idFromValueAndType(value, value.javaClass)
}
override fun idFromValueAndType(value: Any, suggestedType: Class<*>): String {
return when (value) {
is Son -> "son"
is Daughter -> "daughter"
else -> throw IllegalArgumentException()
}
}
override fun idFromBaseType(): String {
throw UnsupportedOperationException()
}
override fun typeFromId(context: DatabindContext, id: String): JavaType {
return when (id) {
"sub" -> context.constructType(Sub::class.java)!!
else -> throw IllegalArgumentException()
}
}
override fun getDescForKnownTypeIds(): String? {
return null
}
override fun getMechanism(): JsonTypeInfo.Id {
return JsonTypeInfo.Id.CUSTOM
}
}
data class Son(
val sonField: String
) : Sub
data class Daughter(
val daughterField: String
) : Sub
```
And my test codes:
```kt
val json = """
{
"type": "sub",
"sub_type": "son",
"son_field": "son"
}
""".trimIndent()
val base = objectMapper.readValue<Base>(json)
```
But type resolver can not using in nested, it throws:
```
com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of `cn.chuanwise.onebot.lib.v11.data.event.Sub` (no Creators, like default constructor, exist): abstract types either need to be mapped to concrete types, have custom deserializer, or contain additional type information
at [Source: REDACTED (`StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION` disabled); line: 2, column: 11]
at com.fasterxml.jackson.databind.exc.InvalidDefinitionException.from(InvalidDefinitionException.java:67)
at com.fasterxml.jackson.databind.DeserializationContext.reportBadDefinition(DeserializationContext.java:1887)
at com.fasterxml.jackson.databind.DatabindContext.reportBadDefinition(DatabindContext.java:414)
at com.fasterxml.jackson.databind.DeserializationContext.handleMissingInstantiator(DeserializationContext.java:1375)
at com.fasterxml.jackson.databind.deser.AbstractDeserializer.deserialize(AbstractDeserializer.java:274)
at com.fasterxml.jackson.databind.jsontype.impl.AsPropertyTypeDeserializer._deserializeTypedForId(AsPropertyTypeDeserializer.java:170)
at com.fasterxml.jackson.databind.jsontype.impl.AsPropertyTypeDeserializer.deserializeTypedFromObject(AsPropertyTypeDeserializer.java:136)
at com.fasterxml.jackson.databind.deser.AbstractDeserializer.deserializeWithType(AbstractDeserializer.java:263)
at com.fasterxml.jackson.databind.deser.impl.TypeWrappedDeserializer.deserialize(TypeWrappedDeserializer.java:74)
at com.fasterxml.jackson.databind.deser.DefaultDeserializationContext.readRootValue(DefaultDeserializationContext.java:342)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4905)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3848)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3831)
at cn.chuanwise.onebot.lib.v11.data.event.EventDataTest.testDeserializeBase(EventDataTest.kt:194)
```
And I can't return the final POJO class Son or Daughter in the BaseTypeIdResolver. Notice that there are 2 main functions in `TypeIdResolver` called `fun idFromValueAndType(value: Any, suggestedType: Class<*>): String` and `fun typeFromId(context: DatabindContext, id: String): JavaType`, and `typeFromId` just know single type id, but we need another field "sub_type".