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
Dzianis Shakinau
08/06/2026, 2:58 PM
what about composition? move duplicated attributes to a separate data class and include it everywhere
b
Bernhard
08/06/2026, 2:58 PM
that's one approach yes, but it also causes deep nesting
Bernhard
08/06/2026, 2:58 PM
I guess what I'm looking for is a compiler plugin?
Bernhard
08/06/2026, 3:30 PM
Ah right I'm currently writing data classes for ktor client so I can't change the shape of the objects
p
phldavies
08/06/2026, 4:00 PM
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