🔴 The Error You're Seeing
Confirm this matches your console output. If it does, you're in the right place.
2026-02-14 10:05:22.120 WARN 8842 --- [nio-8080-exec-2] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'text/plain;charset=UTF-8' not supported]⚡ Quick Fix Works 80% of the time
Set the Content-Type header to application/json in your API client (Postman/curl).
curl -X POST http://localhost:8080/api/users -H "Content-Type: application/json" -d '{"name":"Deva"}'🧠 Why this Happens
Tap to expand the deep technical explanation
The client sent an HTTP request with a Content-Type header (like text/plain or application/xml) that your Spring Boot controller method does not understand. By default, Spring Boot's @RestController expects and parses application/json.
The HITEC City Parking Spot Analogy:
It is like sending a document written in French to a translator who only speaks English. The translator (Spring) rejects the document because they don't support that language (Media Type).
🔁 How to Reproduce Confirm this is your error
Send a request with Content-Type: text/plain to a @PostMapping that consumes application/json. The API returns 415 Unsupported Media Type.
🛠️ Solutions (3 Ways to Fix)
Send the correct Content-Type header
👉 Use this when your Spring Boot code is correct, but the client is sending the wrong header.
If your method expects @RequestBody mapped to an object, Spring needs the client to tell it the data is JSON via the Content-Type: application/json header.
// In Postman: Go to Headers tab -> Add Key: Content-Type, Value: application/json
// In curl: add -H "Content-Type: application/json"Add 'consumes' to your mapping annotation
👉 Use this if you want to strictly restrict an endpoint to only accept JSON.
Explicitly declaring consumes = MediaType.APPLICATION_JSON_VALUE ensures Spring only routes JSON requests to this method.
@PostMapping(value = "/users", consumes = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> createUser(@RequestBody UserRequest request) { ... }Ensure Jackson is on the classpath
👉 Use this if you are sending the correct header but still getting 415.
Spring Boot auto-configures JSON converters using Jackson. If the jackson-databind dependency is missing, Spring doesn't know how to parse JSON.
<!-- pom.xml -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency> <!-- This includes Jackson automatically -->📋 Version Notes
Standard HttpMessageConverter behavior.
Identical behavior, but uses Jakarta Servlet APIs under the hood.
🛡️ How to Prevent This Next Time
Always standardize your API clients to send Content-Type: application/json for POST/PUT requests.