๐Ÿ”ด The Error You're Seeing

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

ERROR LOG2026-03-01 14:22:18.300 WARN 8842 --- [nio-8080-exec-6] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation]

โšก Quick Fix Works 80% of the time

Ensure your API can produce JSON, or change the client's Accept header to application/json.

@GetMapping(value = "/users", produces = MediaType.APPLICATION_JSON_VALUE) public List<User> getUsers() { ... } // Client: Accept: application/json

๐Ÿง  Why this Happens

Tap to expand the deep technical explanation

The client sent an 'Accept' header specifying the response formats it understands (e.g., application/xml). Spring Boot looked at your controller method, realized it could only produce JSON (or the requested format was missing), and returned 406 Not Acceptable to avoid sending data the client can't read.

The HITEC City Parking Spot Analogy:

It is like ordering a pizza in English at a restaurant where the staff only speaks French. The waiter (Spring) apologizes and says they cannot provide the service in that language (format).

๐Ÿ” How to Reproduce Confirm this is your error

Request a resource with Accept: application/xml while your API only produces JSON. Spring returns 406 Not Acceptable with 'Could not find acceptable representation'.

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

Solution 1โœ“ Most common cause

Fix the client Accept header

๐Ÿ‘‰ Use this if the client is asking for XML, but your API only returns JSON.

The client sent an 'Accept: application/xml' header. Spring tried to find a converter to turn your Java object into XML, couldn't find one, and returned 406.

// In Postman/Client: // Go to Headers tab // Accept: application/json
Solution 2

Add Jackson XML dependency

๐Ÿ‘‰ Use this if you genuinely want to support XML responses.

Spring Boot only includes the JSON converter by default. To support XML, you must add jackson-dataformat-xml to your pom.xml.

<dependency> <groupId>com.fasterxml.jackson.dataformat</groupId> <artifactId>jackson-dataformat-xml</artifactId> </dependency>
Solution 3

Check @RequestMapping produces attribute

๐Ÿ‘‰ Use this if you restricted your endpoint to a specific format.

If you explicitly set produces = "application/xml" on your method, but the client asks for JSON, Spring returns 406. Align the produces attribute with what the client wants.

// If client wants JSON, ensure this is set: @GetMapping(value = "/users", produces = MediaType.APPLICATION_JSON_VALUE)

๐Ÿ“‹ Version Notes

Spring Boot 2.x

Uses Jackson 2.x for content negotiation.

Spring Boot 3.x

Uses Jackson 2.15+. Identical behavior.

๐Ÿ›ก๏ธ How to Prevent This Next Time

Standardize your APIs on JSON unless you have a specific need for XML. Ensure frontend clients always send 'Accept: application/json'.

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