KParameter.type returns the reflected KType of a callable parameter. During JSON deserialization, inspect it before passing values to callBy: mismatched types cause IllegalArgumentException, especially for numeric parameters such as Int, Long, and Double. section 12.2.5
Selecting a serializer from the parameter type
fun serializerForType(type: KType): ValueSerializer<out Any?>? = when (type) { typeOf<Byte>() -> ByteSerializer typeOf<Int>() -> IntSerializer typeOf<Boolean>() -> BooleanSerializer else -> null } A deserializer can call serializerForType(param.type), convert JSON values to the constructor parameter's Kotlin type, and then supply the converted value in the callBy argument map. section 12.2.5
Listing 12.10 Getting a serializer based on the type of the value
fun serializerForType(type: KType): ValueSerializer<out Any?>? =
when (type) {
typeOf<Byte>() -> ByteSerializer
typeOf<Int>() -> IntSerializer
typeOf<Boolean>() -> BooleanSerializer
// ...
else -> null
}
Browse the compact type-to-serializer mapping used to connect reflected KType values with built-in deserializers. section 12.2.5
