Would anyone recommendation on how to customize/ex...
# serialization
e
Would anyone recommendation on how to customize/extend generated data class serializers? My json is structured like
Copy code
{
fooProp1,
fooProp2,
barProp1,
barProp2
}
And I'm structuring more OO in Kotlin, such as:
Copy code
data class MyThing(val prop1: String, val prop2: String)

data class Combined(val foo: MyThing, val bar: MyThing)
The data structures have a lot more repetition than shown in this example so it would be great to find something where I can take the automatically generated serializers and simply tell the combined deserializer to deserialize MyThing by prepending the name of its property name. This would probably be done in the Combined serializer, maybe giving it a modified decoder instance or something? We're wanting to target K/N in the future so want to avoid reflection, currently I'm using reflection in a custom Serializer class which iterates over the reflected object properties and uses those to figure out the keys. Any direction would be helpful, I just can't seem to figure out this usecase of wanting to extend the generated serializers, documentation or an article would help too.
d
You could use a
JsonTransformingSerializer
to tranform the json to something nicer to parse.