I am building some API with Spring Boot, but I get some errors about Content-Type when I try to query with Postman.
@RequestMapping(path = "/verify", method = RequestMethod.POST, consumes = "text/xml", produces = "application/json")
String verify(@RequestBody Map<String, Object> payload, HttpServletRequest request) {}
I don't understand where there is the problem.
I noticed that the error disappears when I remove @RequestBody as parameter of method. Why?
I would simply:
- send XML to API
- receive JSON from API
Best Answer
If you're getting and Error related to
Content-Type
, then I surely assume that you use HTTP REST as mean to communicate between your components.The
Content-Type
is related to Content Negotiation topic within HTTP REST.Content Negotiation topic within HTTP REST means that clients and services must agree on representation media type. i.e they need to agree how to communicate with each other, what will be the content of each payload that is sent and received between the parties.
Client specifies what it wants through
Accept
headerServer specifies what produces through
Content-Type
header