how do you share structure between data classes? o...
# getting-started
b
how do you share structure between data classes? oftentimes I feel like I want to copy paste attributes from one data class to another and put an interface on top; is there a way to do that?
d
what about composition? move duplicated attributes to a separate data class and include it everywhere
b
that's one approach yes, but it also causes deep nesting
I guess what I'm looking for is a compiler plugin?
Ah right I'm currently writing data classes for ktor client so I can't change the shape of the objects
p
If you're using JSON and KotlinX Serialization, you can possibly use composition on your data classes but a JsonTransformingSerializer to unwrap/wrap fields as needed
❤️ 1