I'm trying to group common properties together on ...
# serialization
b
I'm trying to group common properties together on a data class and want to flatten that to other objects, e.g.
Copy code
{
  "id": "",
  "name": "",
  "email": ""
}
should serialize onto
Copy code
data class User(val id: String, val common: Common) { data class Common(val name: String, val email: String)}
what am I looking for? is there an API for that use case or do I need to handroll everything?
e
there isn't an equivalent to
@JsonUnwrapped
like other frameworks, so you'll have to do it yourself
it's not that much work with a surrogate serializer though
or alternatively, if you can structure your classes like
Copy code
interface Common {
    val name: String,
    val email: String,
}

@Serializable
data class User(
    val id: String,
    override val name: String,
    override val email: String,
) : Common
then it'll directly produce the JSON you want
b
right, that requires me to duplicate 30 attributes on 10 classes though