We are creating rest api's with Spring Boot. We have three layers in our project(Repository, Service and Controller).
Lets say I have GetUser api in my controller that return UserDTO
object.
@GetMapping
public UserDTO getUser() {
return userService.getUser();
}
Whether userService.getUser()
returns UserDTO
object or it returns User
object and it is converted to UserDTO
object in the controller? Which one is better way?
Shortly, domain object to DTO object conversion, should be done in service layer or controller layer?