๐ด The Error You're Seeing
Confirm this matches your console output. If it does, you're in the right place.
2026-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)
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/jsonAdd 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>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
Uses Jackson 2.x for content negotiation.
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'.