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:
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
header
Server specifies what produces through Content-Type
header
Add following line in your application.properties:
logging.file = myapp.log
Restart your server, make a request. Check myapp.log to find what is failing. For me, I got this error:
2018-05-08 07:08:34.404 WARN 348 --- [http-nio-8080-exec-5] .c.j.MappingJackson2HttpMessageConverter : Failed to evaluate Jackson deserialization for type [[simple type, class com.atta.entity.User]]: com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot handle managed/back reference 'defaultReference': back reference type (java.util.List) not compatible with managed type (com.atta.entity.State)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With