pajatopmr
01/24/2021, 1:27 PMpajatopmr
01/26/2021, 10:01 AMSomeSerializer
. With the format + modules approach, I would write: format.encodeToString(data)
,
val format = Json { serializersModule = module }
private val module = SerializersModule {
contextua(SomeSerializer)
}
And I would note that SomeSerializer
is more complex in format + module case.pajatopmr
01/26/2021, 10:01 AMpajatopmr
01/26/2021, 10:02 AMVsevolod Tolstopyatov [JB]
01/29/2021, 11:50 AMpajatopmr
01/29/2021, 7:16 PMJsonTransformingPolymorphicSerializer
and these are a bit more complicated. The use case is to transform a huge pile of TypeScript interfaces (LSP) to Kotlin. fwiw, it took me a while to grok KXS and solve my problem but now I'm in the happy camper camp. 🙂
/**
* Use to avoid type discriminants and to register the implementation in the scope of the interface.
*/
object ContentColorRegistrationOptionsSerializer :
JsonContentPolymorphicSerializer<ColorRegistrationOptions>(ColorRegistrationOptions::class) {
override fun selectDeserializer(element: JsonElement) = ColorRegistrationOptionsImpl.serializer()
}
The code is open source on GitLab for anyone who wants to offer up ideas on how to make it simpler. The code is clean but there is a lot of it!.