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
Check If a Given Time Lies Between Two Times Regardless of Date
Regular Expression for Uppercase Letters in a String
Spring Rest - Create Zip File and Send It to the Client
Remove Duplicate Values from Hashmap in Java
How to Get Values of All Elements from Xml String in Java
What Is the Most Elegant Way to Check If All Values in a Boolean Array Are True
How to Multiply a and B With My Recursive Method
Mockito - Nullpointerexception When Stubbing Method
Null Can Not Be Compared to Double - Why
Finding Repeated Words on a String and Counting the Repetitions
Java - How to Write My Arraylist to a File, and Read (Load) That File to the Original Arraylist
How to Store a String Longer Than 4000 Characters in an Oracle Database Using Java/Jdbc
How to Print Even and Odd Position Characters of an Array of Strings in Java
Convert String With Dot or Comma to Float Number
How to Configure Hikaricp in My Spring Boot App in My Application.Properties Files