[resolved] Hi all, While applying a clean architec...
# ksp
u
[resolved] Hi all, While applying a clean architecture, it is cumbersome to write code to transform the model from Data to Domain. Can I use KSP to automatically generate a mapper code? Think only if the data model and the domain model have the same properties.
g
Yes it is possible (also I presume you could use simply a typealias or reuse the data class if it's 1-1)
u
Thank you so much It was very helpful. If that's the case, 1. Is it possible to have a list of properties? 2. Is it possible for a domain model to receive some properties of the data model?
g
1. You can have the name and the type of the signature of each members (property or method) with info like visibility or backing field. Should be enough to generate a mapper. 2. Not sure to understand the question.
u
This is the case Data
Copy code
UserDTO(val id: Int, val name: String)
Domain
Copy code
User(val id)
g
Alright, so you want to generate a UserDTO.toDomain() function that uses the primary constructor of User. That's totally doable, given there is a perfect matching of names between the 2 classes. If it's not the processor could generate an error to show the matching issue, or simply avoid generating the mapping function.