Request and Response Model Classes

Json payload to be sent to web service endpoint for user creation would be look like

{
"firstName" : "Claire"
"lastName" : "Min"
"email" : "test@test.com"
"password" : "123"
}

Web service endpoint will accept the Jason payload and convert it into Java object which is used to persist into database.

Since Spring Boot framework does all of conversions like Json/xml to Java or Java to Json/xml automatically, what needs to be done for the conversions is to create Java class that matches each fields (firstName, lastName, ...).


* Method to handle HTTP Post Request

ex ) In RestController,
@PostMapping
public String createUser(@RequestBody UserDetailsRequestModel userDetails) {}

This method will be triggered when it receives HTTP Post request. In order for the method to read the body of the HTTP request, and convert the Json body into Java object(UserDetailsRequestModel), @RequestBody is needed.


UserDetailsRequestModel : Java bean involving the fields matching with request body.


- What is Java Bean?
Java Bean is a normal Java class which has private properties with its public getter and setter. generally used as a helper class.


com.firstProject.ui.model.request : Package for all the model classes used for converting incoming Json documents into Java objects.


Response Model is to create Json payload and send it back to client as response.
contain some additional details confirming that user details have been stored in DB
(make sure not include sensitive information in response model class - reason why separate request and response model class)






Comments

Popular posts from this blog

Portlet Edit Mode (Portlet preference) to replace Portlet configuration

GoGo Shell & What can be deleted in Liferay Instance