We take separate model for request and response these are basically from UI point of view. Suppose we get the data from end user like : firstName, lastName, email, password.
We get this data in JSON formate so we have to convert this JSON object to java object for that we create a separate model object in the package ui.model.request. and it will also used by spring framework to convert JSON object to Java object.
Once we persist the data then we get some response back but in that response we. have like pkId of table but we don't want to send this in our response so we can't use a single entity that we used to perisit our data. So we create a new package with ui.model.response and we will copy that required fields and this will used to convert from Java object to JSON and it will be sent back to spring framework
Here incoming request like from end user
Now this incoming request received by method called createUser(); and @RequestBody annotation will take this request as JSON and it will map to UserDetailsRequestModel java bean and will convert JSON to java Object.
Similarly UserDto(basically this bean is carry out on different layer in our project like from controller to service to repository layer. It consists of some additional fields like encryptedPassword, emailVerificatioToke etc. )
Once we save our entity object which is constructed from UserDto bean. once we save we receive UserEntity but we will copy files from UserEntity bean to UserDto and we will copy the field from UserDto to UserRest (this is basically model which is sent back and spring framework will take that java object and convert into a json format and send back the response.)like this which consist of information that we want to expose only.
We get this data in JSON formate so we have to convert this JSON object to java object for that we create a separate model object in the package ui.model.request. and it will also used by spring framework to convert JSON object to Java object.
Once we persist the data then we get some response back but in that response we. have like pkId of table but we don't want to send this in our response so we can't use a single entity that we used to perisit our data. So we create a new package with ui.model.response and we will copy that required fields and this will used to convert from Java object to JSON and it will be sent back to spring framework
Here incoming request like from end user
Now this incoming request received by method called createUser(); and @RequestBody annotation will take this request as JSON and it will map to UserDetailsRequestModel java bean and will convert JSON to java Object.
Similarly UserDto(basically this bean is carry out on different layer in our project like from controller to service to repository layer. It consists of some additional fields like encryptedPassword, emailVerificatioToke etc. )
Once we save our entity object which is constructed from UserDto bean. once we save we receive UserEntity but we will copy files from UserEntity bean to UserDto and we will copy the field from UserDto to UserRest (this is basically model which is sent back and spring framework will take that java object and convert into a json format and send back the response.)like this which consist of information that we want to expose only.
Comments
Post a Comment