In a Spring Boot RestController, I'm using the springframework class ResponseEntity to return the response for the endpoint call.
I recently found out there are two ways to instantiate this class.
Using the constructor :
response = new ResponseEntity<MyDto>(myDto, myHeaders, HttpStatus.OK);
Using the static builder :
response = ResponseEntity.ok().headers(myHeaders).body(myDto);
The resulting instance seams to be the same.
I wonder, what are the pros and cons of each ? In which situation should I use preferably one or the other ?