public final class MediaType
extends java.lang.Object
The type, subtype, and parameter names are all canonicalized to lowercase strings.
Modifier and Type | Method and Description |
---|---|
boolean |
equals(java.lang.Object o) |
static MediaType |
from(java.lang.String value)
Create a parsed MediaType from the given string.
|
java.util.Map<java.lang.String,java.lang.String> |
getParameters()
Gets the immutable map of parameters.
|
java.lang.String |
getSubtype()
Gets the "subtype" of the media type.
|
java.lang.String |
getSubtypeWithoutSuffix()
Gets the "subtype" of the media type with no structured syntax suffix.
|
java.util.Optional<java.lang.String> |
getSuffix()
Gets the optional structured syntax suffix.
|
java.lang.String |
getType()
Gets the "type" of the media type.
|
int |
hashCode() |
static boolean |
isJson(java.lang.String mediaType)
Detects if the given media type string is JSON, meaning it
is "application/json" or uses the "+json" structured syntax
suffix.
|
java.lang.String |
toString() |
public static MediaType from(java.lang.String value)
value
- Media type to parse (e.g., application/json).java.lang.RuntimeException
- if the media type is invalid.public static boolean isJson(java.lang.String mediaType)
mediaType
- Media type to parse and test if it's JSON.public java.lang.String getType()
public java.lang.String getSubtype()
public java.lang.String getSubtypeWithoutSuffix()
For example given, "application/foo+json", this method returns "foo". Given "application/foo+baz+json", this method returns "foo+baz".
public java.util.Map<java.lang.String,java.lang.String> getParameters()
public java.util.Optional<java.lang.String> getSuffix()
For example given, "application/foo+json", this method returns
"json". Given "application/foo+baz+json", this method returns
"json". Given "application/json", this method returns an empty
Optional
.
public java.lang.String toString()
toString
in class java.lang.Object
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object