Scrivio Interview library
DebuggingFoundations6 min read · updated 12 November 2026

A POST with a JSON body returns 415 Unsupported Media Type. What are the likely causes?

Spring answers 415 Unsupported Media Type when it cannot accept the request body's media type for that endpoint. The usual causes are a client that sent no Content-Type or a different one (text/plain, or form data instead of application/json), a mapping whose consumes condition does not include the sent type, or no HttpMessageConverter that can read that type into the parameter, for example when Jackson is missing. By contrast, 400 means the type was accepted but the body itself was malformed or could not be converted.

Why this question is asked

415 errors are common when a new client starts calling an API, and they waste time because the JSON looks perfectly fine. The answer is almost never in the JSON; it is in the headers or in the server's setup. Interviewers ask this to check that we know how Spring decides whether it can read a body. In this answer, we will recap the Content-Type header and message converters, walk through how Spring handles a request body, look at each cause with a way to reproduce it, and compare 415 with 400 and 406.

1A Quick Recap of Content-Type and Message Converters

Every HTTP request with a body should carry a Content-Type header that says what the bytes are: application/json for JSON, application/x-www-form-urlencoded for an HTML form, multipart/form-data for file uploads. The server cannot guess reliably, so it trusts this header.

On the server, a @RequestBody parameter is filled by an HttpMessageConverter, a small object that can read one or more media types into Java objects. Spring Boot registers a Jackson converter for application/json and application/*+json when Jackson is on the classpath, which spring-boot-starter-web provides. When a request arrives, Spring looks for a converter that can read the request's Content-Type into the parameter's type. If none can, the request fails with HttpMediaTypeNotSupportedException, which Spring maps to 415.

2How Spring Handles a Request Body

There are actually two places where Spring checks the media type, and knowing both explains every cause below. First, during handler mapping, Spring checks the consumes condition of @RequestMapping or @PostMapping, if there is one. Then, during argument resolution, it looks for a converter for the @RequestBody parameter.

Step throughWhere a 415 or 400 comes from
  1. Request arrives with a bodyPOST /orders
  2. Mapping has consumes?@PostMapping(consumes = ...)
    YesContent-Type must match itNoAny type passes mapping
  3. Content-Type allowed by consumes?Only checked when consumes is set
    YesGo to argument resolutionNo415 from handler mapping
  4. A converter can read this type?Jackson for application/json
    YesRead the bodyNo415 HttpMediaTypeNotSupportedException
  5. Body is valid JSON and converts?Syntax and types
    YesCall the handlerNo400 HttpMessageNotReadableException

5 steps in order. Play them, or step through them one at a time.

3Cause 1: The Client Sent the Wrong Content-Type

This is the most common cause by far. Many HTTP clients do not set Content-Type: application/json automatically. curl with -d sends application/x-www-form-urlencoded. A JavaScript fetch with a string body sends text/plain;charset=UTF-8 unless headers are set. Postman sends whatever the body type dropdown says.

Shell
curl -X POST http://localhost:8080/orders -d '{"customerId":"c-1"}'
// Content-Type: application/x-www-form-urlencoded (curl's default for -d)
// -> 415 Unsupported Media Type
// Content-Type 'application/x-www-form-urlencoded;charset=UTF-8' is not supported
curl -X POST http://localhost:8080/orders -H 'Content-Type: application/json' -d '{"customerId":"c-1"}'
// -> 201 Created
fetch('/orders', { method: 'POST', body: JSON.stringify(order) })
// Content-Type: text/plain;charset=UTF-8 -> 415
fetch('/orders', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(order) })
// -> 201

Notice that Spring's error message names the type it received. Reading that line is the fastest diagnosis: if it says text/plain or x-www-form-urlencoded, the fix is on the client. Enabling DEBUG logging for org.springframework.web shows the same detail on the server side.

4Cause 2: A consumes Condition That Does Not Match

A mapping can restrict which types it accepts. That is useful when two methods share a path and differ by type, but a too narrow consumes rejects legitimate clients.

Java
@PostMapping(path = "/orders", consumes = "application/vnd.shop.order+json")
ResponseEntity<OrderDto> create(@RequestBody CreateOrder req) { ... }
// Client sends Content-Type: application/json
// -> 415: the mapping only consumes application/vnd.shop.order+json
@PostMapping(path = "/orders", consumes = { MediaType.APPLICATION_JSON_VALUE, "application/vnd.shop.order+json" })
// -> both types are accepted

Notice that the Jackson converter could read application/json perfectly well; the request is rejected earlier, by the mapping. So when a 415 appears for an endpoint that has a consumes attribute, check it first. It is also worth checking any custom filters or gateways, which sometimes rewrite or drop headers.

5Cause 3: No Converter Can Read the Type

If no converter supports the media type and target type, the request fails even when the header is correct. In a normal Spring Boot web application this is rare, but it happens in a few situations: a project that excluded Jackson or uses spring-boot-starter-web without its default JSON starter; a custom WebMvcConfigurer that overrides configureMessageConverters and replaces the defaults instead of adding to them; a client sending XML, application/xml, when only the JSON converter is present; or a parameter type that Jackson cannot construct at all, which Jackson reports while checking whether it can read the type.

Spring Boot 4 moved to Jackson 3, with new package names, so mixing Jackson 2 configuration with a Boot 4 application can also leave the expected converter missing. Check your version when a 415 appears right after an upgrade.

6How 415 Differs From 400 and 406

A 400 Bad Request means Spring accepted the media type and found a converter, but the body could not be read: broken JSON syntax, a string where a number was expected, or a value that does not fit an enum. Spring throws HttpMessageNotReadableException for these, and a failed @Valid check gives MethodArgumentNotValidException, both 400. So the rule of thumb is that 415 is about the type of the body, and 400 is about its content.

A 406 Not Acceptable is the mirror image of 415 on the response side: the client's Accept header asks for a type that no converter can produce, or that the produces condition does not include.

YAML
Content-Type: application/json, body {"customerId": } -> 400 (JSON parse error)
Content-Type: application/json, body {"quantity": "two"} -> 400 (cannot convert "two" to int)
Content-Type: text/plain, body {"customerId": "c-1"} -> 415 (type not supported)
Accept: application/xml, only JSON converter registered -> 406 (cannot produce XML)

7Follow-up questions

Why does Spring not just try JSON when the header is missing?

A request with a body and no Content-Type is treated as application/octet-stream, raw bytes. Guessing would hide client bugs and could misread data, so Spring follows the declared type. The client should always declare it.

How would you make the error clearer for clients?

Enable problem details with spring.mvc.problemdetails.enabled=true, or handle HttpMediaTypeNotSupportedException in a @RestControllerAdvice, so the response body says which type was received and which types are supported. Spring also adds an Accept header listing the supported media types to a 415 response, which helps client developers.

8Conclusion

In this answer, we saw that 415 Unsupported Media Type means Spring could not accept the request body's media type: the client sent no or a different Content-Type, the mapping's consumes condition did not include it, or no HttpMessageConverter could read it, for example because Jackson was missing or the converters were replaced. We also saw that 400 is about malformed content once the type is accepted, and 406 is the response-side mirror of 415.

What to say in the interviewAbout 90 seconds aloud

Open with

A 415 means Spring didn't accept the media type of the request body, so I'd look at the headers and the server setup before the JSON itself. The most common cause is the client: it didn't send Content-Type: application/json, or sent something else. curl with -d sends form-urlencoded by default, and fetch with a string body sends text/plain, so both get a 415 even though the JSON is fine.

Then, if they want more

Spring's error message names the type it received, which usually settles it. The second cause is a consumes condition on the mapping that doesn't include the type the client sends, for example a vendor media type only; then the request is rejected during handler mapping before any converter is involved.

The third is that no HttpMessageConverter can read the type into the parameter, which happens if Jackson isn't on the classpath, if someone overrode configureMessageConverters and dropped the defaults, if the client sends XML without an XML converter, or after a Jackson version change.

I'd contrast that with 400, which means the type was accepted and a converter found, but the body was malformed or didn't convert, like broken syntax or a string for a number. And 406 is the mirror on the response side, when the Accept header asks for a type we can't produce.

About this answer

Last updated
12 November 2026
Versions it names
Spring Boot 4
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "A POST with a JSON body returns 415 Unsupported Media Type. What are the likely causes?": https://scrivio-interview-library.netlify.app/spring-boot/rest-controllers/9bc43c27a0/