๐Ÿ”ด The Error You're Seeing

Confirm this matches your console output. If it does, you're in the right place.

ERROR LOG2026-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"}'

๐Ÿ› ๏ธ Solutions (3 Ways to Fix)

Solution 1โœ“ Most common cause

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"
Solution 2

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) { ... }
Solution 3

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

Spring Boot 2.x

Standard HttpMessageConverter behavior.

Spring Boot 3.x

Identical behavior, but uses Jakarta Servlet APIs under the hood.

๐Ÿง  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 Prevent This Next Time

Always standardize your API clients to send Content-Type: application/json for POST/PUT requests.

Course Search
Search across all chapters & stages
๐Ÿ“–

Search the course

Type any topic โ€” branching, stash, rebase, hooks โ€” and jump straight to that chapter.

merge branchesgit stashundo commitrebase