Here is an abstract example of what I do in Kotlin. I am happy to translate to java if you would like. I am thinking if the pattern we are discussing can give me a concise repleca of interface X and it's DTO. It does not need to be an inner class I just thought it made it easy to find. I am OK with class being the source of the meta data. This is used for model to resource translation. I have other patterns like this for posting graph like objects. Not working directly with a POJO let's me build impls in the form of class Zebra and because they are not the data class themselves I can override them or delegate to them since they implement my interface. I like to use a DTO only to send data over the wire.
```kotlin
//Playground of ideas skip to line 48 for and example of Entity to Resource adapter.
interface X {
val l: String
val m: String
data class Dto(override val l: String, override val m: String): X {
constructor(source: X): this(source.l, source.m)
}
}
interface Y {
val n: String
val o: String
data class Dto(override val n: String, override val o: String): Y {
constructor(source: Y): this(source.n, source.o)
}
}
interface Z {
val l: String
val m2: String //This is an example of +/- of a field
val n: String
val o: String
data class Dto(override val l: String, override val m2: String, override val n: String, override val o: String): Z {
constructor(source: Z): this(source.l, source.m2, source.n, source.o)
}
}
//Here we will compose an implementation of Z based on delegation to X and Y
// Z gets (l) from X, (n, o) from Z and we will implement m2 on our own
class Zebra(val x: X, val y: Y): X by x, Y by y, Z {
//We can lazy load
override val m2 get() = m + "2"
}
//Since the DTO implements our X interface this is one way we can roll
val x = X.Dto("Lenny", "Mark")
//or we can do this which allows us to lazy load n in this case
val y = object: Y {
override val n: String
get() = "Nancy"
override val o = "Oprah"
}
//Since Zebra implement Z we can construct a DTO from it.
val zebra = Z.Dto(Zebra(x, y))
```