Package org.springframework.web.server

# Class UnsupportedMediaTypeStatusException

java.lang.Object
java.lang.Throwable
java.lang.Exception
java.lang.RuntimeException
org.springframework.core.NestedRuntimeException
org.springframework.web.ErrorResponseException
org.springframework.web.server.ResponseStatusException
org.springframework.web.server.UnsupportedMediaTypeStatusException

All Implemented Interfaces:
  `Serializable`, `ErrorResponse`

public class UnsupportedMediaTypeStatusException extends ResponseStatusException
Exception for errors that fit response status 415 (unsupported media type).

Since:
  5.0
Author:
  Rossen Stoyanchev
See Also:
  - Serialized Form

## Nested Class Summary

## Nested classes/interfaces inherited from interface org.springframework.web.ErrorResponse

`ErrorResponse.Builder, ErrorResponse.Interceptor`

## Constructor Summary

Constructors
Constructor
Description
`UnsupportedMediaTypeStatusException(String reason)`
Constructor for when the specified Content-Type is invalid.
`UnsupportedMediaTypeStatusException(String reason, List<MediaType> supportedTypes)`
Constructor for when the specified Content-Type is invalid.
`UnsupportedMediaTypeStatusException(MediaType contentType, List<MediaType> supportedTypes)`
Constructor for when the Content-Type can be parsed but is not supported.
`UnsupportedMediaTypeStatusException(MediaType contentType, List<MediaType> supportedTypes, org.springframework.core.ResolvableType bodyType)`
Constructor for when trying to encode from or decode to a specific Java type.
`UnsupportedMediaTypeStatusException(MediaType contentType, List<MediaType> supportedTypes, org.springframework.core.ResolvableType bodyType, HttpMethod method)`
Constructor for when trying to encode from or decode to a specific Java type.
`UnsupportedMediaTypeStatusException(MediaType contentType, List<MediaType> supportedTypes, HttpMethod method)`
Constructor that provides the HTTP method.

## Method Summary

Modifier and Type
Method
Description
`org.springframework.core.ResolvableType`
`getBodyType()`
Return the body type in the context of which this exception was generated.
`MediaType`
`getContentType()`
Return the request Content-Type header if it was parsed successfully, or `null` otherwise.
`HttpHeaders`
`getHeaders()`
Return HttpHeaders with an "Accept" header that documents the supported media types, if available, or an empty instance otherwise.
`HttpHeaders`
`getResponseHeaders()`
Deprecated.
as of 6.0 in favor of `getHeaders()`
`List<MediaType>`
`getSupportedMediaTypes()`
Return the list of supported content types in cases when the Content-Type header is parsed but not supported, or an empty list otherwise.

### Methods inherited from class org.springframework.web.server.ResponseStatusException

`getMessage, getReason, updateAndGetBody`

### Methods inherited from class org.springframework.web.ErrorResponseException

`getBody, getDetailMessageArguments, getDetailMessageCode, getStatusCode, setDetail, setInstance, setTitle, setType`

### Methods inherited from class org.springframework.core.NestedRuntimeException

`contains, getMostSpecificCause, getRootCause`

### Methods inherited from class java.lang.Throwable

`addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

### Methods inherited from interface org.springframework.web.ErrorResponse

`getDetailMessageArguments, getTitleMessageCode, getTypeMessageCode`

## Constructor Details

### UnsupportedMediaTypeStatusException

public UnsupportedMediaTypeStatusException(@Nullable String reason)
Constructor for when the specified Content-Type is invalid.

### UnsupportedMediaTypeStatusException

public UnsupportedMediaTypeStatusException(@Nullable String reason, List<MediaType> supportedTypes)
Constructor for when the specified Content-Type is invalid.

Since:
  6.0.5

### UnsupportedMediaTypeStatusException

public UnsupportedMediaTypeStatusException(@Nullable MediaType contentType, List<MediaType> supportedTypes)
Constructor for when the Content-Type can be parsed but is not supported.

### UnsupportedMediaTypeStatusException

public UnsupportedMediaTypeStatusException(@Nullable MediaType contentType, List<MediaType> supportedTypes, @Nullable org.springframework.core.ResolvableType bodyType)
Constructor for when trying to encode from or decode to a specific Java type.

Since:
  5.1

### UnsupportedMediaTypeStatusException

public UnsupportedMediaTypeStatusException(@Nullable MediaType contentType, List<MediaType> supportedTypes, @Nullable HttpMethod method)
Constructor that provides the HTTP method.

Since:
  5.3.6

### UnsupportedMediaTypeStatusException

public UnsupportedMediaTypeStatusException(@Nullable MediaType contentType, List<MediaType> supportedTypes, @Nullable org.springframework.core.ResolvableType bodyType, @Nullable HttpMethod method)
Constructor for when trying to encode from or decode to a specific Java type.

Since:
  5.3.6

## Method Details

### getContentType

@Nullable public MediaType getContentType()
Return the request Content-Type header if it was parsed successfully, or `null` otherwise.

### getSupportedMediaTypes

public List<MediaType> getSupportedMediaTypes()
Return the list of supported content types in cases when the Content-Type header is parsed but not supported, or an empty list otherwise.

### getBodyType

@Nullable public org.springframework.core.ResolvableType getBodyType()
Return the body type in the context of which this exception was generated.

This is applicable when the exception was raised as a result trying to encode from or decode to a specific Java type.

Returns:
  the body type, or `null` if not available
Since:
  5.1

### getHeaders

public HttpHeaders getHeaders()
Return HttpHeaders with an "Accept" header that documents the supported media types, if available, or an empty instance otherwise.

Specified by:
  `getHeaders` in interface `ErrorResponse`
Overrides:
  `getHeaders` in class `ResponseStatusException`

### getResponseHeaders

@Deprecated(since="6.0") public HttpHeaders getResponseHeaders()
Deprecated.
as of 6.0 in favor of `getHeaders()`
Delegates to `getHeaders()`.

Overrides:
  `getResponseHeaders` in class `ResponseStatusException`