Package org.springframework.http

# Class MediaType

java.lang.Object
org.springframework.util.MimeType
org.springframework.http.MediaType

All Implemented Interfaces:
  `Serializable`, `Comparable<org.springframework.util.MimeType>`

public class MediaType extends org.springframework.util.MimeType implements Serializable
A subclass of `MimeType` that adds support for quality parameters as defined in the HTTP specification.

This class is meant to reference media types supported by Spring Framework. If your application or library relies on other media types defined in RFCs, please use `parseMediaType(String)` or a custom utility class.

Since:
  3.0
Author:
  Arjen Poutsma, Juergen Hoeller, Rossen Stoyanchev, Sebastien Deleuze, Kazuki Shimizu, Sam Brannen, Hyoungjune Kim
See Also:
  - HTTP 1.1: Semantics and Content, section 3.1.1.1
  - Serialized Form

## Nested Class Summary

## Nested classes/interfaces inherited from class org.springframework.util.MimeType

`org.springframework.util.MimeType.SpecificityComparator<T extends org.springframework.util.MimeType>`

## Field Summary

Fields
Modifier and Type
Field
Description
`static final MediaType`
`ALL`
Public constant media type that includes all media ranges (i.e.
`static final String`
`ALL_VALUE`
A String equivalent of `ALL`.
`static final MediaType`
`APPLICATION_ATOM_XML`
Public constant media type for `application/atom+xml`.
`static final String`
`APPLICATION_ATOM_XML_VALUE`
A String equivalent of `APPLICATION_ATOM_XML`.
`static final MediaType`
`APPLICATION_CBOR`
Public constant media type for `application/cbor`.
`static final String`
`APPLICATION_CBOR_VALUE`
A String equivalent of `APPLICATION_CBOR`.
`static final MediaType`
`APPLICATION_FORM_URLENCODED`
Public constant media type for `application/x-www-form-urlencoded`.
`static final String`
`APPLICATION_FORM_URLENCODED_VALUE`
A String equivalent of `APPLICATION_FORM_URLENCODED`.
`static final MediaType`
`APPLICATION_GRAPHQL`
Deprecated, for removal: This API element is subject to removal in a future version.
as of 6.0.3, in favor of `APPLICATION_GRAPHQL_RESPONSE`
`static final MediaType`
`APPLICATION_GRAPHQL_RESPONSE`
Public constant media type for `application/graphql-response+json`.
`static final String`
`APPLICATION_GRAPHQL_RESPONSE_VALUE`
A String equivalent of `APPLICATION_GRAPHQL_RESPONSE`.
`static final String`
`APPLICATION_GRAPHQL_VALUE`
Deprecated, for removal: This API element is subject to removal in a future version.
as of 6.0.3, in favor of `APPLICATION_GRAPHQL_RESPONSE_VALUE`
`static final MediaType`
`APPLICATION_JSON`
Public constant media type for `application/json`.
`static final MediaType`
`APPLICATION_JSON_UTF8`
Deprecated.
as of 5.2 in favor of `APPLICATION_JSON` since major browsers like Chrome now comply with the specification and interpret correctly UTF-8 special characters without requiring a `charset=UTF-8` parameter.
`static final String`
`APPLICATION_JSON_UTF8_VALUE`
Deprecated.
as of 5.2 in favor of `APPLICATION_JSON_VALUE` since major browsers like Chrome now comply with the specification and interpret correctly UTF-8 special characters without requiring a `charset=UTF-8` parameter.
`static final String`
`APPLICATION_JSON_VALUE`
A String equivalent of `APPLICATION_JSON`.
`static final MediaType`
`APPLICATION_NDJSON`
Public constant media type for `application/x-ndjson`.
`static final String`
`APPLICATION_NDJSON_VALUE`
A String equivalent of `APPLICATION_NDJSON`.
`static final MediaType`
`APPLICATION_OCTET_STREAM`
Public constant media type for `application/octet-stream`.
`static final String`
`APPLICATION_OCTET_STREAM_VALUE`
A String equivalent of `APPLICATION_OCTET_STREAM`.
`static final MediaType`
`APPLICATION_PDF`
Public constant media type for `application/pdf`.
`static final String`
`APPLICATION_PDF_VALUE`
A String equivalent of `APPLICATION_PDF`.
`static final MediaType`
`APPLICATION_PROBLEM_JSON`
Public constant media type for `application/problem+json`.
`static final MediaType`
`APPLICATION_PROBLEM_JSON_UTF8`
Deprecated.
as of 5.2 in favor of `APPLICATION_PROBLEM_JSON` since major browsers like Chrome now comply with the specification and interpret correctly UTF-8 special characters without requiring a `charset=UTF-8` parameter.
`static final String`
`APPLICATION_PROBLEM_JSON_UTF8_VALUE`
Deprecated.
as of 5.2 in favor of `APPLICATION_PROBLEM_JSON_VALUE` since major browsers like Chrome now comply with the specification and interpret correctly UTF-8 special characters without requiring a `charset=UTF-8` parameter.
`static final String`
`APPLICATION_PROBLEM_JSON_VALUE`
A String equivalent of `APPLICATION_PROBLEM_JSON`.
`static final MediaType`
`APPLICATION_PROBLEM_XML`
Public constant media type for `application/problem+xml`.
`static final String`
`APPLICATION_PROBLEM_XML_VALUE`
A String equivalent of `APPLICATION_PROBLEM_XML`.
`static final MediaType`
`APPLICATION_PROTOBUF`
Public constant media type for `application/x-protobuf`.
`static final String`
`APPLICATION_PROTOBUF_VALUE`
A String equivalent of `APPLICATION_PROTOBUF`.
`static final MediaType`
`APPLICATION_RSS_XML`
Public constant media type for `application/rss+xml`.
`static final String`
`APPLICATION_RSS_XML_VALUE`
A String equivalent of `APPLICATION_RSS_XML`.
`static final MediaType`
`APPLICATION_STREAM_JSON`
Deprecated.
as of 5.3, see notice on `APPLICATION_STREAM_JSON_VALUE`.
`static final String`
`APPLICATION_STREAM_JSON_VALUE`
Deprecated.
as of 5.3 since it originates from the W3C Activity Streams specification which has a more specific purpose and has been since replaced with a different mime type.
`static final MediaType`
`APPLICATION_XHTML_XML`
Public constant media type for `application/xhtml+xml`.
`static final String`
`APPLICATION_XHTML_XML_VALUE`
A String equivalent of `APPLICATION_XHTML_XML`.
`static final MediaType`
`APPLICATION_XML`
Public constant media type for `application/xml`.
`static final String`
`APPLICATION_XML_VALUE`
A String equivalent of `APPLICATION_XML`.
`static final MediaType`
`APPLICATION_YAML`
Public constant media type for `application/yaml`.
`static final String`
`APPLICATION_YAML_VALUE`
A String equivalent of `APPLICATION_YAML`.
`static final MediaType`
`IMAGE_GIF`
Public constant media type for `image/gif`.
`static final String`
`IMAGE_GIF_VALUE`
A String equivalent of `IMAGE_GIF`.
`static final MediaType`
`IMAGE_JPEG`
Public constant media type for `image/jpeg`.
`static final String`
`IMAGE_JPEG_VALUE`
A String equivalent of `IMAGE_JPEG`.
`static final MediaType`
`IMAGE_PNG`
Public constant media type for `image/png`.
`static final String`
`IMAGE_PNG_VALUE`
A String equivalent of `IMAGE_PNG`.
`static final MediaType`
`MULTIPART_FORM_DATA`
Public constant media type for `multipart/form-data`.
`static final String`
`MULTIPART_FORM_DATA_VALUE`
A String equivalent of `MULTIPART_FORM_DATA`.
`static final MediaType`
`MULTIPART_MIXED`
Public constant media type for `multipart/mixed`.
`static final String`
`MULTIPART_MIXED_VALUE`
A String equivalent of `MULTIPART_MIXED`.
`static final MediaType`
`MULTIPART_RELATED`
Public constant media type for `multipart/related`.
`static final String`
`MULTIPART_RELATED_VALUE`
A String equivalent of `MULTIPART_RELATED`.
`static final Comparator<MediaType>`
`QUALITY_VALUE_COMPARATOR`
Deprecated, for removal: This API element is subject to removal in a future version.
as of 6.0, with no direct replacement
`static final Comparator<MediaType>`
`SPECIFICITY_COMPARATOR`
Deprecated, for removal: This API element is subject to removal in a future version.
as of 6.0, with no direct replacement
`static final MediaType`
`TEXT_EVENT_STREAM`
Public constant media type for `text/event-stream`.
`static final String`
`TEXT_EVENT_STREAM_VALUE`
A String equivalent of `TEXT_EVENT_STREAM`.
`static final MediaType`
`TEXT_HTML`
Public constant media type for `text/html`.
`static final String`
`TEXT_HTML_VALUE`
A String equivalent of `TEXT_HTML`.
`static final MediaType`
`TEXT_MARKDOWN`
Public constant media type for `text/markdown`.
`static final String`
`TEXT_MARKDOWN_VALUE`
A String equivalent of `TEXT_MARKDOWN`.
`static final MediaType`
`TEXT_PLAIN`
Public constant media type for `text/plain`.
`static final String`
`TEXT_PLAIN_VALUE`
A String equivalent of `TEXT_PLAIN`.
`static final MediaType`
`TEXT_XML`
Public constant media type for `text/xml`.
`static final String`
`TEXT_XML_VALUE`
A String equivalent of `TEXT_XML`.

### Fields inherited from class org.springframework.util.MimeType

`WILDCARD_TYPE`

## Constructor Summary

Constructors
Constructor
Description
`MediaType(String type)`
Create a new `MediaType` for the given primary type.
`MediaType(String type, String subtype)`
Create a new `MediaType` for the given primary type and subtype.
`MediaType(String type, String subtype, double qualityValue)`
Create a new `MediaType` for the given type, subtype, and quality value.
`MediaType(String type, String subtype, Charset charset)`
Create a new `MediaType` for the given type, subtype, and character set.
`MediaType(String type, String subtype, Map<String,String> parameters)`
Create a new `MediaType` for the given type, subtype, and parameters.
`MediaType(MediaType other, Charset charset)`
Copy-constructor that copies the type, subtype and parameters of the given `MediaType`, and allows to set the specified character set.
`MediaType(MediaType other, Map<String,String> parameters)`
Copy-constructor that copies the type and subtype of the given `MediaType`, and allows for different parameters.
`MediaType(org.springframework.util.MimeType mimeType)`
Create a new `MediaType` for the given `MimeType`.

## Method Summary

Modifier and Type
Method
Description
`static MediaType`
`asMediaType(org.springframework.util.MimeType mimeType)`
Re-create the given mime type as a media type.
`static List<MediaType>`
`asMediaTypes(List<org.springframework.util.MimeType> mimeTypes)`
Re-create the given mime types as media types.
`protected void`
`checkParameters(String parameter, String value)`
`MediaType`
`copyQualityValue(MediaType mediaType)`
Return a replica of this instance with the quality value of the given `MediaType`.
`double`
`getQualityValue()`
Return the quality factor, as indicated by a `q` parameter, if any.
`boolean`
`includes(MediaType other)`
Indicate whether this `MediaType` includes the given media type.
`boolean`
`isCompatibleWith(MediaType other)`
Indicate whether this `MediaType` is compatible with the given media type.
`boolean`
`isLessSpecific(org.springframework.util.MimeType other)`
Indicates whether this `MediaType` more specific than the given type.
`boolean`
`isMoreSpecific(org.springframework.util.MimeType other)`
Indicates whether this `MediaType` more specific than the given type.
`static MediaType`
`parseMediaType(String mediaType)`
Parse the given String into a single `MediaType`.
`static List<MediaType>`
`parseMediaTypes(String mediaTypes)`
Parse the comma-separated string into a list of `MediaType` objects.
`static List<MediaType>`
`parseMediaTypes(List<String> mediaTypes)`
Parse the given list of (potentially) comma-separated strings into a list of `MediaType` objects.
`MediaType`
`removeQualityValue()`
Return a replica of this instance with its quality value removed.
`static void`
`sortByQualityValue(List<MediaType> mediaTypes)`
Deprecated, for removal: This API element is subject to removal in a future version.
as of 6.0, with no direct replacement
`static void`
`sortBySpecificity(List<MediaType> mediaTypes)`
Deprecated, for removal: This API element is subject to removal in a future version.
as of 6.0, in favor of `MimeTypeUtils.sortBySpecificity(List)`
`static void`
`sortBySpecificityAndQuality(List<MediaType> mediaTypes)`
Deprecated, for removal: This API element is subject to removal in a future version.
as of 6.0, in favor of `MimeTypeUtils.sortBySpecificity(List)`
`static String`
`toString(Collection<MediaType> mediaTypes)`
Return a string representation of the given list of `MediaType` objects.
`static MediaType`
`valueOf(String value)`
Parse the given String value into a `MediaType` object, with this method name following the 'valueOf' naming convention (as supported by `ConversionService`).

### Methods inherited from class org.springframework.util.MimeType

`appendTo, compareTo, equals, equalsTypeAndSubtype, getCharset, getParameter, getParameters, getSubtype, getSubtypeSuffix, getType, hashCode, includes, isCompatibleWith, isConcrete, isPresentIn, isWildcardSubtype, isWildcardType, toString, unquote`

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

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

## Field Details

### ALL

public static final MediaType ALL
Public constant media type that includes all media ranges (i.e. "*/*").

### ALL_VALUE

public static final String ALL_VALUE
A String equivalent of `ALL`.

See Also:
  - Constant Field Values

### APPLICATION_ATOM_XML

public static final MediaType APPLICATION_ATOM_XML
Public constant media type for `application/atom+xml`.

### APPLICATION_ATOM_XML_VALUE

public static final String APPLICATION_ATOM_XML_VALUE
A String equivalent of `APPLICATION_ATOM_XML`.

See Also:
  - Constant Field Values

### APPLICATION_CBOR

public static final MediaType APPLICATION_CBOR
Public constant media type for `application/cbor`.

Since:
  5.2

### APPLICATION_CBOR_VALUE

public static final String APPLICATION_CBOR_VALUE
A String equivalent of `APPLICATION_CBOR`.

Since:
  5.2
See Also:
  - Constant Field Values

### APPLICATION_FORM_URLENCODED

public static final MediaType APPLICATION_FORM_URLENCODED
Public constant media type for `application/x-www-form-urlencoded`.

### APPLICATION_FORM_URLENCODED_VALUE

public static final String APPLICATION_FORM_URLENCODED_VALUE
A String equivalent of `APPLICATION_FORM_URLENCODED`.

See Also:
  - Constant Field Values

### APPLICATION_GRAPHQL

@Deprecated(since="6.0.3", forRemoval=true) public static final MediaType APPLICATION_GRAPHQL
Deprecated, for removal: This API element is subject to removal in a future version.
as of 6.0.3, in favor of `APPLICATION_GRAPHQL_RESPONSE`
Public constant media type for `application/graphql+json`.

Since:
  5.3.19
See Also:
  - GraphQL over HTTP spec change

### APPLICATION_GRAPHQL_VALUE

@Deprecated(since="6.0.3", forRemoval=true) public static final String APPLICATION_GRAPHQL_VALUE
Deprecated, for removal: This API element is subject to removal in a future version.
as of 6.0.3, in favor of `APPLICATION_GRAPHQL_RESPONSE_VALUE`
A String equivalent of `APPLICATION_GRAPHQL`.

Since:
  5.3.19
See Also:
  - Constant Field Values

### APPLICATION_GRAPHQL_RESPONSE

public static final MediaType APPLICATION_GRAPHQL_RESPONSE
Public constant media type for `application/graphql-response+json`.

Since:
  6.0.3
See Also:
  - GraphQL over HTTP spec

### APPLICATION_GRAPHQL_RESPONSE_VALUE

public static final String APPLICATION_GRAPHQL_RESPONSE_VALUE
A String equivalent of `APPLICATION_GRAPHQL_RESPONSE`.

Since:
  6.0.3
See Also:
  - Constant Field Values

### APPLICATION_JSON

public static final MediaType APPLICATION_JSON
Public constant media type for `application/json`.

### APPLICATION_JSON_VALUE

public static final String APPLICATION_JSON_VALUE
A String equivalent of `APPLICATION_JSON`.

See Also:
  - `APPLICATION_JSON_UTF8_VALUE`
  - Constant Field Values

### APPLICATION_JSON_UTF8

@Deprecated public static final MediaType APPLICATION_JSON_UTF8
Deprecated.
as of 5.2 in favor of `APPLICATION_JSON` since major browsers like Chrome now comply with the specification and interpret correctly UTF-8 special characters without requiring a `charset=UTF-8` parameter.
Public constant media type for `application/json;charset=UTF-8`.

### APPLICATION_JSON_UTF8_VALUE

@Deprecated public static final String APPLICATION_JSON_UTF8_VALUE
Deprecated.
as of 5.2 in favor of `APPLICATION_JSON_VALUE` since major browsers like Chrome now comply with the specification and interpret correctly UTF-8 special characters without requiring a `charset=UTF-8` parameter.
A String equivalent of `APPLICATION_JSON_UTF8`.

See Also:
  - Constant Field Values

### APPLICATION_OCTET_STREAM

public static final MediaType APPLICATION_OCTET_STREAM
Public constant media type for `application/octet-stream`.

### APPLICATION_OCTET_STREAM_VALUE

public static final String APPLICATION_OCTET_STREAM_VALUE
A String equivalent of `APPLICATION_OCTET_STREAM`.

See Also:
  - Constant Field Values

### APPLICATION_PDF

public static final MediaType APPLICATION_PDF
Public constant media type for `application/pdf`.

Since:
  4.3

### APPLICATION_PDF_VALUE

public static final String APPLICATION_PDF_VALUE
A String equivalent of `APPLICATION_PDF`.

Since:
  4.3
See Also:
  - Constant Field Values

### APPLICATION_PROBLEM_JSON

public static final MediaType APPLICATION_PROBLEM_JSON
Public constant media type for `application/problem+json`.

Since:
  5.0
See Also:
  - Problem Details for HTTP APIs, 6.1. application/problem+json

### APPLICATION_PROBLEM_JSON_VALUE

public static final String APPLICATION_PROBLEM_JSON_VALUE
A String equivalent of `APPLICATION_PROBLEM_JSON`.

Since:
  5.0
See Also:
  - Constant Field Values

### APPLICATION_PROBLEM_JSON_UTF8

@Deprecated public static final MediaType APPLICATION_PROBLEM_JSON_UTF8
Deprecated.
as of 5.2 in favor of `APPLICATION_PROBLEM_JSON` since major browsers like Chrome now comply with the specification and interpret correctly UTF-8 special characters without requiring a `charset=UTF-8` parameter.
Public constant media type for `application/problem+json`.

Since:
  5.0
See Also:
  - Problem Details for HTTP APIs, 6.1. application/problem+json

### APPLICATION_PROBLEM_JSON_UTF8_VALUE

@Deprecated public static final String APPLICATION_PROBLEM_JSON_UTF8_VALUE
Deprecated.
as of 5.2 in favor of `APPLICATION_PROBLEM_JSON_VALUE` since major browsers like Chrome now comply with the specification and interpret correctly UTF-8 special characters without requiring a `charset=UTF-8` parameter.
A String equivalent of `APPLICATION_PROBLEM_JSON_UTF8`.

Since:
  5.0
See Also:
  - Constant Field Values

### APPLICATION_PROBLEM_XML

public static final MediaType APPLICATION_PROBLEM_XML
Public constant media type for `application/problem+xml`.

Since:
  5.0
See Also:
  - Problem Details for HTTP APIs, 6.2. application/problem+xml

### APPLICATION_PROBLEM_XML_VALUE

public static final String APPLICATION_PROBLEM_XML_VALUE
A String equivalent of `APPLICATION_PROBLEM_XML`.

Since:
  5.0
See Also:
  - Constant Field Values

### APPLICATION_PROTOBUF

public static final MediaType APPLICATION_PROTOBUF
Public constant media type for `application/x-protobuf`.

Since:
  6.0

### APPLICATION_PROTOBUF_VALUE

public static final String APPLICATION_PROTOBUF_VALUE
A String equivalent of `APPLICATION_PROTOBUF`.

Since:
  6.0
See Also:
  - Constant Field Values

### APPLICATION_RSS_XML

public static final MediaType APPLICATION_RSS_XML
Public constant media type for `application/rss+xml`.

Since:
  4.3.6

### APPLICATION_RSS_XML_VALUE

public static final String APPLICATION_RSS_XML_VALUE
A String equivalent of `APPLICATION_RSS_XML`.

Since:
  4.3.6
See Also:
  - Constant Field Values

### APPLICATION_NDJSON

public static final MediaType APPLICATION_NDJSON
Public constant media type for `application/x-ndjson`.

Since:
  5.3

### APPLICATION_NDJSON_VALUE

public static final String APPLICATION_NDJSON_VALUE
A String equivalent of `APPLICATION_NDJSON`.

Since:
  5.3
See Also:
  - Constant Field Values

### APPLICATION_STREAM_JSON

@Deprecated public static final MediaType APPLICATION_STREAM_JSON
Deprecated.
as of 5.3, see notice on `APPLICATION_STREAM_JSON_VALUE`.
Public constant media type for `application/stream+json`.

Since:
  5.0

### APPLICATION_STREAM_JSON_VALUE

@Deprecated public static final String APPLICATION_STREAM_JSON_VALUE
Deprecated.
as of 5.3 since it originates from the W3C Activity Streams specification which has a more specific purpose and has been since replaced with a different mime type. Use `APPLICATION_NDJSON` as a replacement or any other line-delimited JSON format (for example, JSON Lines, JSON Text Sequences).
A String equivalent of `APPLICATION_STREAM_JSON`.

Since:
  5.0
See Also:
  - Constant Field Values

### APPLICATION_XHTML_XML

public static final MediaType APPLICATION_XHTML_XML
Public constant media type for `application/xhtml+xml`.

### APPLICATION_XHTML_XML_VALUE

public static final String APPLICATION_XHTML_XML_VALUE
A String equivalent of `APPLICATION_XHTML_XML`.

See Also:
  - Constant Field Values

### APPLICATION_XML

public static final MediaType APPLICATION_XML
Public constant media type for `application/xml`.

### APPLICATION_XML_VALUE

public static final String APPLICATION_XML_VALUE
A String equivalent of `APPLICATION_XML`.

See Also:
  - Constant Field Values

### APPLICATION_YAML

public static final MediaType APPLICATION_YAML
Public constant media type for `application/yaml`.

Since:
  6.2

### APPLICATION_YAML_VALUE

public static final String APPLICATION_YAML_VALUE
A String equivalent of `APPLICATION_YAML`.

Since:
  6.2
See Also:
  - Constant Field Values

### IMAGE_GIF

public static final MediaType IMAGE_GIF
Public constant media type for `image/gif`.

### IMAGE_GIF_VALUE

public static final String IMAGE_GIF_VALUE
A String equivalent of `IMAGE_GIF`.

See Also:
  - Constant Field Values

### IMAGE_JPEG

public static final MediaType IMAGE_JPEG
Public constant media type for `image/jpeg`.

### IMAGE_JPEG_VALUE

public static final String IMAGE_JPEG_VALUE
A String equivalent of `IMAGE_JPEG`.

See Also:
  - Constant Field Values

### IMAGE_PNG

public static final MediaType IMAGE_PNG
Public constant media type for `image/png`.

### IMAGE_PNG_VALUE

public static final String IMAGE_PNG_VALUE
A String equivalent of `IMAGE_PNG`.

See Also:
  - Constant Field Values

### MULTIPART_FORM_DATA

public static final MediaType MULTIPART_FORM_DATA
Public constant media type for `multipart/form-data`.

### MULTIPART_FORM_DATA_VALUE

public static final String MULTIPART_FORM_DATA_VALUE
A String equivalent of `MULTIPART_FORM_DATA`.

See Also:
  - Constant Field Values

### MULTIPART_MIXED

public static final MediaType MULTIPART_MIXED
Public constant media type for `multipart/mixed`.

Since:
  5.2

### MULTIPART_MIXED_VALUE

public static final String MULTIPART_MIXED_VALUE
A String equivalent of `MULTIPART_MIXED`.

Since:
  5.2
See Also:
  - Constant Field Values

### MULTIPART_RELATED

public static final MediaType MULTIPART_RELATED
Public constant media type for `multipart/related`.

Since:
  5.2.5

### MULTIPART_RELATED_VALUE

public static final String MULTIPART_RELATED_VALUE
A String equivalent of `MULTIPART_RELATED`.

Since:
  5.2.5
See Also:
  - Constant Field Values

### TEXT_EVENT_STREAM

public static final MediaType TEXT_EVENT_STREAM
Public constant media type for `text/event-stream`.

Since:
  4.3.6
See Also:
  - Server-Sent Events

### TEXT_EVENT_STREAM_VALUE

public static final String TEXT_EVENT_STREAM_VALUE
A String equivalent of `TEXT_EVENT_STREAM`.

Since:
  4.3.6
See Also:
  - Constant Field Values

### TEXT_HTML

public static final MediaType TEXT_HTML
Public constant media type for `text/html`.

### TEXT_HTML_VALUE

public static final String TEXT_HTML_VALUE
A String equivalent of `TEXT_HTML`.

See Also:
  - Constant Field Values

### TEXT_MARKDOWN

public static final MediaType TEXT_MARKDOWN
Public constant media type for `text/markdown`.

Since:
  4.3

### TEXT_MARKDOWN_VALUE

public static final String TEXT_MARKDOWN_VALUE
A String equivalent of `TEXT_MARKDOWN`.

Since:
  4.3
See Also:
  - Constant Field Values

### TEXT_PLAIN

public static final MediaType TEXT_PLAIN
Public constant media type for `text/plain`.

### TEXT_PLAIN_VALUE

public static final String TEXT_PLAIN_VALUE
A String equivalent of `TEXT_PLAIN`.

See Also:
  - Constant Field Values

### TEXT_XML

public static final MediaType TEXT_XML
Public constant media type for `text/xml`.

### TEXT_XML_VALUE

public static final String TEXT_XML_VALUE
A String equivalent of `TEXT_XML`.

See Also:
  - Constant Field Values

### QUALITY_VALUE_COMPARATOR

@Deprecated(since="6.0", forRemoval=true) public static final Comparator<MediaType> QUALITY_VALUE_COMPARATOR
Deprecated, for removal: This API element is subject to removal in a future version.
as of 6.0, with no direct replacement
Comparator used by `sortByQualityValue(List)`.

### SPECIFICITY_COMPARATOR

@Deprecated(since="6.0", forRemoval=true) public static final Comparator<MediaType> SPECIFICITY_COMPARATOR
Deprecated, for removal: This API element is subject to removal in a future version.
as of 6.0, with no direct replacement
Comparator used by `sortBySpecificity(List)`.

## Constructor Details

### MediaType

public MediaType(String type)
Create a new `MediaType` for the given primary type.

The subtype is set to "*", parameters empty.

Parameters:
  `type` - the primary type
Throws:
  `IllegalArgumentException` - if any of the parameters contain illegal characters

### MediaType

public MediaType(String type, String subtype)
Create a new `MediaType` for the given primary type and subtype.

The parameters are empty.

Parameters:
  `type` - the primary type
  `subtype` - the subtype
Throws:
  `IllegalArgumentException` - if any of the parameters contain illegal characters

### MediaType

public MediaType(String type, String subtype, Charset charset)
Create a new `MediaType` for the given type, subtype, and character set.

Parameters:
  `type` - the primary type
  `subtype` - the subtype
  `charset` - the character set
Throws:
  `IllegalArgumentException` - if any of the parameters contain illegal characters

### MediaType

public MediaType(String type, String subtype, double qualityValue)
Create a new `MediaType` for the given type, subtype, and quality value.

Parameters:
  `type` - the primary type
  `subtype` - the subtype
  `qualityValue` - the quality value
Throws:
  `IllegalArgumentException` - if any of the parameters contain illegal characters

### MediaType

public MediaType(MediaType other, Charset charset)
Copy-constructor that copies the type, subtype and parameters of the given `MediaType`, and allows to set the specified character set.

Parameters:
  `other` - the other media type
  `charset` - the character set
Throws:
  `IllegalArgumentException` - if any of the parameters contain illegal characters
Since:
  4.3

### MediaType

public MediaType(MediaType other, @Nullable Map<String,String> parameters)
Copy-constructor that copies the type and subtype of the given `MediaType`, and allows for different parameters.

Parameters:
  `other` - the other media type
  `parameters` - the parameters, may be `null`
Throws:
  `IllegalArgumentException` - if any of the parameters contain illegal characters

### MediaType

public MediaType(String type, String subtype, @Nullable Map<String,String> parameters)
Create a new `MediaType` for the given type, subtype, and parameters.

Parameters:
  `type` - the primary type
  `subtype` - the subtype
  `parameters` - the parameters, may be `null`
Throws:
  `IllegalArgumentException` - if any of the parameters contain illegal characters

### MediaType

public MediaType(org.springframework.util.MimeType mimeType)
Create a new `MediaType` for the given `MimeType`. The type, subtype and parameters information is copied and `MediaType`-specific checks on parameters are performed.

Parameters:
  `mimeType` - the MIME type
Throws:
  `IllegalArgumentException` - if any of the parameters contain illegal characters
Since:
  5.3

## Method Details

### checkParameters

protected void checkParameters(String parameter, String value)

Overrides:
  `checkParameters` in class `org.springframework.util.MimeType`

### getQualityValue

public double getQualityValue()
Return the quality factor, as indicated by a `q` parameter, if any. Defaults to `1.0`.

Returns:
  the quality factor as double value

### isMoreSpecific

public boolean isMoreSpecific(org.springframework.util.MimeType other)
Indicates whether this `MediaType` more specific than the given type.

1. if this media type has a quality factor higher than the other, then this method returns `true`.
2. if this media type has a quality factor lower than the other, then this method returns `false`.
3. if this mime type has a wildcard type, and the other does not, then this method returns `false`.
4. if this mime type does not have a wildcard type, and the other does, then this method returns `true`.
5. if this mime type has a wildcard type, and the other does not, then this method returns `false`.
6. if this mime type does not have a wildcard type, and the other does, then this method returns `true`.
7. if the two mime types have identical type and subtype, then the mime type with the most parameters is more specific than the other.
8. Otherwise, this method returns `false`.

Overrides:
  `isMoreSpecific` in class `org.springframework.util.MimeType`
Parameters:
  `other` - the `MimeType` to be compared
Returns:
  the result of the comparison
Since:
  6.0
See Also:
  - `isLessSpecific(MimeType)`
  - HTTP 1.1: Semantics and Content, section 5.3.2

### isLessSpecific

public boolean isLessSpecific(org.springframework.util.MimeType other)
Indicates whether this `MediaType` more specific than the given type.

1. if this media type has a quality factor higher than the other, then this method returns `false`.
2. if this media type has a quality factor lower than the other, then this method returns `true`.
3. if this mime type has a wildcard type, and the other does not, then this method returns `true`.
4. if this mime type does not have a wildcard type, and the other does, then this method returns `false`.
5. if this mime type has a wildcard type, and the other does not, then this method returns `true`.
6. if this mime type does not have a wildcard type, and the other does, then this method returns `false`.
7. if the two mime types have identical type and subtype, then the mime type with the least parameters is less specific than the other.
8. Otherwise, this method returns `false`.

Overrides:
  `isLessSpecific` in class `org.springframework.util.MimeType`
Parameters:
  `other` - the `MimeType` to be compared
Returns:
  the result of the comparison
Since:
  6.0
See Also:
  - `isMoreSpecific(MimeType)`
  - HTTP 1.1: Semantics and Content, section 5.3.2

### includes

public boolean includes(@Nullable MediaType other)
Indicate whether this `MediaType` includes the given media type.

For instance, `text/*` includes `text/plain` and `text/html`, and `application/*+xml` includes `application/soap+xml`, etc. This method is not symmetric.

Simply calls `MimeType.includes(MimeType)` but declared with a `MediaType` parameter for binary backwards compatibility.

Parameters:
  `other` - the reference media type with which to compare
Returns:
  `true` if this media type includes the given media type; `false` otherwise

### isCompatibleWith

public boolean isCompatibleWith(@Nullable MediaType other)
Indicate whether this `MediaType` is compatible with the given media type.

For instance, `text/*` is compatible with `text/plain`, `text/html`, and vice versa. In effect, this method is similar to `includes(org.springframework.http.MediaType)`, except that it is symmetric.

Simply calls `MimeType.isCompatibleWith(MimeType)` but declared with a `MediaType` parameter for binary backwards compatibility.

Parameters:
  `other` - the reference media type with which to compare
Returns:
  `true` if this media type is compatible with the given media type; `false` otherwise

### copyQualityValue

public MediaType copyQualityValue(MediaType mediaType)
Return a replica of this instance with the quality value of the given `MediaType`.

Returns:
  the same instance if the given MediaType doesn't have a quality value, or a new one otherwise

### removeQualityValue

public MediaType removeQualityValue()
Return a replica of this instance with its quality value removed.

Returns:
  the same instance if the media type doesn't contain a quality value, or a new one otherwise

### valueOf

public static MediaType valueOf(String value)
Parse the given String value into a `MediaType` object, with this method name following the 'valueOf' naming convention (as supported by `ConversionService`).

Parameters:
  `value` - the string to parse
Throws:
  `InvalidMediaTypeException` - if the media type value cannot be parsed
See Also:
  - `parseMediaType(String)`

### parseMediaType

public static MediaType parseMediaType(String mediaType)
Parse the given String into a single `MediaType`.

Parameters:
  `mediaType` - the string to parse
Returns:
  the media type
Throws:
  `InvalidMediaTypeException` - if the media type value cannot be parsed

### parseMediaTypes

public static List<MediaType> parseMediaTypes(@Nullable String mediaTypes)
Parse the comma-separated string into a list of `MediaType` objects.

This method can be used to parse an Accept or Content-Type header.

Parameters:
  `mediaTypes` - the string to parse
Returns:
  the list of media types
Throws:
  `InvalidMediaTypeException` - if the media type value cannot be parsed

### parseMediaTypes

public static List<MediaType> parseMediaTypes(@Nullable List<String> mediaTypes)
Parse the given list of (potentially) comma-separated strings into a list of `MediaType` objects.

This method can be used to parse an Accept or Content-Type header.

Parameters:
  `mediaTypes` - the string to parse
Returns:
  the list of media types
Throws:
  `InvalidMediaTypeException` - if the media type value cannot be parsed
Since:
  4.3.2

### asMediaTypes

public static List<MediaType> asMediaTypes(List<org.springframework.util.MimeType> mimeTypes)
Re-create the given mime types as media types.

Since:
  5.0

### asMediaType

public static MediaType asMediaType(org.springframework.util.MimeType mimeType)
Re-create the given mime type as a media type.

Since:
  5.0

### toString

public static String toString(Collection<MediaType> mediaTypes)
Return a string representation of the given list of `MediaType` objects.

This method can be used to for an `Accept` or `Content-Type` header.

Parameters:
  `mediaTypes` - the media types to create a string representation for
Returns:
  the string representation

### sortBySpecificity

@Deprecated(since="6.0", forRemoval=true) public static void sortBySpecificity(List<MediaType> mediaTypes)
Deprecated, for removal: This API element is subject to removal in a future version.
as of 6.0, in favor of `MimeTypeUtils.sortBySpecificity(List)`
Sorts the given list of `MediaType` objects by specificity.

Given two media types:

1. if either media type has a wildcard type, then the media type without the wildcard is ordered before the other.
2. if the two media types have different types, then they are considered equal and remain their current order.
3. if either media type has a wildcard subtype, then the media type without the wildcard is sorted before the other.
4. if the two media types have different subtypes, then they are considered equal and remain their current order.
5. if the two media types have different quality value, then the media type with the highest quality value is ordered before the other.
6. if the two media types have a different amount of parameters, then the media type with the most parameters is ordered before the other.

For example:

> audio/basic < audio/* < */*

> audio/* < audio/*;q=0.7; audio/*;q=0.3

> audio/basic;level=1 < audio/basic

> audio/basic == text/html

> audio/basic == audio/wave

Parameters:
  `mediaTypes` - the list of media types to be sorted

### sortByQualityValue

@Deprecated(since="6.0", forRemoval=true) public static void sortByQualityValue(List<MediaType> mediaTypes)
Deprecated, for removal: This API element is subject to removal in a future version.
as of 6.0, with no direct replacement
Sorts the given list of `MediaType` objects by quality value.

Given two media types:

1. if the two media types have different quality value, then the media type with the highest quality value is ordered before the other.
2. if either media type has a wildcard type, then the media type without the wildcard is ordered before the other.
3. if the two media types have different types, then they are considered equal and remain their current order.
4. if either media type has a wildcard subtype, then the media type without the wildcard is sorted before the other.
5. if the two media types have different subtypes, then they are considered equal and remain their current order.
6. if the two media types have a different amount of parameters, then the media type with the most parameters is ordered before the other.

Parameters:
  `mediaTypes` - the list of media types to be sorted
See Also:
  - `getQualityValue()`

### sortBySpecificityAndQuality

@Deprecated(since="6.0", forRemoval=true) public static void sortBySpecificityAndQuality(List<MediaType> mediaTypes)
Deprecated, for removal: This API element is subject to removal in a future version.
as of 6.0, in favor of `MimeTypeUtils.sortBySpecificity(List)`
Sorts the given list of `MediaType` objects by specificity as the primary criteria and quality value the secondary.