Brandon Saunders
07/24/2020, 7:45 AMBrandon Saunders
07/24/2020, 8:31 AMNikky
07/24/2020, 9:07 AM@Serializable(with=Fruit.Companion::class)
but then i guess every .serializer() call on there will give you that and you effectively hides the original
there is also parts of approach 1 that might be useful to you.. specifically val serializersModule = SerializersModule { }
in there you can define what serializers to use for classes, mostly used for external classes.. but maybe this could allow you to use 2 serializers alongside each otherBrandon Saunders
07/24/2020, 9:32 AMobject EntitySerializer : KSerializer<Entity> {
override fun deserialize(decoder: Decoder): Entity {
val input = decoder as? JsonInput
?: throw SerializationException("Expected JsonInput for ${decoder::class}")
val jsonObject = input.decodeJson() as? JsonObject
?: throw SerializationException("Expected JsonObject for ${input.decodeJson()::class}")
val foo = decoder.json.parse(Entity.serializer(), jsonObject.toString())
foo.originalJSON = jsonObject.toString()
return foo
}
}
and then used
@file:UseSerializers(EntitySerializer::class)
in all the classes where I had lists of Entities and couldn't reference the EntitySerializer directly