I want to access the request body object of my REST endpoint, which is already deserialized.
My REST controller looks like this:
@RequestMapping(value = "car/{id}", method = RequestMethod.PUT)
public ResponseEntity updateCar(@RequestBody Car car, @PathVariable("id") String carId) {
// My update logic, how i update the car object in database
// with the retrieved request body.
// Here i want to access the raw request body e.g. the JSON string
}
Edit:
The Car POJO:
public class Car {
private String id;
private String name;
private String color;
private List<String> additions = new ArrayList<>();
// setters and getters
}
When i want to make a partial update, e.g a PUT request like this:
curl -X PUT \
-H "Content-Type: application/json" \
-d "{ \"color\" : \"Green\" }" \
http://localhost:8080/car/1234
After the deserialization of the request body above, the additions
field is an empty list although i didn't specified it. If i could access the raw json request body, then i can check whether the additions
field is specified or not.
Is it possible to access the raw request body after it was deserialized?