I have created Rest API using Spring Boot & Data JPA.
It's working fine if requested from Postman responds as JSON format, but when I request from coding using Resttemplate it responds as XML format, then I try to add
@PostMapping(value = "/xxx", produces = MediaType.APPLICATION_JSON_VALUE)
Then, I try to request using Resttemplate again it responds in JSON format.
My question what is the matter if I don't use produces = MediaType.APPLICATION_JSON_VALUE)
, before I don't use it, and my services work fine.
I using Spring version 2.5.7
Controller
@PostMapping(value = "/xxx")
public ResponseEntity<ResponseXXX> calculateFxRate(@RequestBody XXX xxx,
@RequestHeader Map<String, String> headers) {
ResponseXXX xxx = new ResponseXXX();
try {
return new ResponseEntity<>(xxx, HttpStatus.OK);
} catch (Exception e) {
return new ResponseEntity<>(xxx, HttpStatus.OK);
}
}