In my REST API in Spring Boot. I have made three methods, GET, POST & PUT.
I want to find user details (which is saved in Person class) by giving userId and userSubId and display the result (either in case of success or failed) as response.
Also, I want to insert user details using POST method and display the result as response.
And finally, I want to edit the existing details using PUT method by giving userId and userSubId and display the result (either success or failed) as response.
To display the results (either in case of success or failed), I have created a seaparate RESPONSE classs with 'message', 'details', 'status', 'timestamp' & 'errors' variables.
BUT, I want to customize my RESPONSE to be sent to client like this:
In case of Success, it should be like:
{
"message": "Success",
"details": [
{
"userId": 1,
"userSubId": 2,
"firstName": "John",
"middleName": "Doe",
"lastName": "Dean",
"street": "Lincoln Street",
"city": "Cetrump",
"state": "Louis",
"country": "Zaparta",
"zipCode": "776655",
}
],
"status": "Ok",
"timestamp": 2012-04-21T18:25:43-05:00,
"errorCode": 200
}
In case of Failed, it should be like:
{
"message": "Failed",
"details": [
{
"userId": 2,
"userSubId": 6
}
],
"status": "Not Found",
"timestamp": 2013-04-21T18:25:43-05:00,
"errorCode": 404
}
That is, the 'details' should be holding all the data in case of GET method and only few data (like userId and userSubId) in case of POST and PUT methods. And, I am not be able to do that. Please guide.