hfhbd
03/01/2023, 10:22 AM@Serializable
data class Foo(@MyFormat(Custom::class) val bar: Int)
object Custom: KSerializer<Int> { .. }
With Json, I want to use native integer handling: {"bar": 42
}` but my format should produce 4242
.@Contextual
but this only works only on a type, eg Int but you can't use different contextual serializers for the same type, eg Int.
@Serializable
data class Foo(@Contextual val bar: Int, @Contextual val other: Int)
object BarCustom: KSerializer<Int> { .. }
object OtherCustom: KSerializer<Int> { .. }
MyFormat(serializerModule = SerializersModule {
contextual(Int::class, BarCustom)
}
Derek Ellis
03/01/2023, 12:04 PMencoder is JsonEncoder
and doing something different than if encoder is MyFormatEncoder
)hfhbd
03/01/2023, 1:32 PM