[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
glureau
11/25/2022, 5:23 PM
Yes it is possible (also I presume you could use simply a typealias or reuse the data class if it's 1-1)
u
최상록
11/25/2022, 5:36 PM
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
Grégory Lureau
11/25/2022, 7:20 PM
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
최상록
11/26/2022, 2:20 AM
This is the case
Data
Copy code
UserDTO(val id: Int, val name: String)
Domain
Copy code
User(val id)
g
glureau
11/28/2022, 7:40 AM
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.