Spring Boot Unsupported Media Type With @Requestbody

Spring boot: Getting 415 unsupported Media type

Solved! I accidentally had two setters defined with different data types.

Unsupported Media type 415 @RequestBody Not working But @RequestParam is working

I found the mistake in my configuration file.
adding <mvc:annotation-driven /> solved the problem.

Explanation :

My program was running well but problem was on Mapping the String (Json) into java objects. So there was some issue in default Mapping classes. Although, jackson was present in class-path, It wasn't working.

<mvc:annotation-driven />

this tag would register the HandlerMapping and HandlerAdapter required to dispatch requests to your @Controllers. In addition, it also applies some defaults based on what is present in your classpath. Such as: Support for reading and writing JSON, if Jackson is on the classpath.

415 unsupported media type angular spring boot POST PUT http methods

Hi guys finally I found the problem
I removed @JsonManagedReference in a class related to one of the classes related to mine ,I really recommend not to work with it try to use @JsonIgnore instead

"Unsupported Media Type" in spring boot - Windows

"Why email instead of eMail" - That is just the default behavior of Jackson.

"what to do to get eMail instead of email" - You can control Jackson's behavior through annotations on the POJO. The relevant here is @JsonProperty. See this question for details.

"How to POST correctly, what I'm doing wrong?" - You mean PUT instead of POST, don't you? Define the content type consumed by the method:

@PutMapping(path="/user/{id}", consumes = MediaType.APPLICATION_JSON_VALUE)
User replaceUser(@RequestBody User newUser, @PathVariable Long id) {
...
}

Also, as was pointed out by @rimonmostafiz, you need to redefine your curl call, escaping the quotation:

curl -X PUT -H "Content-Type: application/json" -d "{ \"email\": \"asd\", \"passwordHash\": \"sad\" }"

As an aside: Please limit yourself to one question per post in the future.



Related Topics



Leave a reply



Submit