I have a class `data class(val foo: String, ...)` ...
# serialization
a
I have a class
data class(val foo: String, ...)
and in one context I need field
foo
to be serialized as
bar
(don’t need deserialization), but in other cases it should be de-/serialized as usual. How is it possible to achieve this?
p
Create a KSerializer and use it depending on your context
a
That won’t help. Serializers are protocol agnostic and only define how values are serialized, it doesn’t have any control over how fields are named in json.
p
Ah you want to name it differently and not serialize it differently. Then go with a JsonTransformingSerializer