public class ParameterContentNegotiationStrategy extends AbstractMappingContentNegotiationStrategy
ContentNegotiationStrategy
that resolves a query parameter to a key
to be used to look up a media type. The default parameter name is format
.Constructor and Description |
---|
ParameterContentNegotiationStrategy(Map<String,MediaType> mediaTypes)
Create an instance with the given map of file extensions and media types.
|
Modifier and Type | Method and Description |
---|---|
protected String |
getMediaTypeKey(NativeWebRequest request)
Extract a key from the request to use to look up media types.
|
String |
getParameterName() |
protected void |
handleMatch(String mediaTypeKey,
MediaType mediaType)
Override to provide handling when a key is successfully resolved via
MappingMediaTypeFileExtensionResolver.lookupMediaType(java.lang.String) . |
protected MediaType |
handleNoMatch(NativeWebRequest request,
String key)
Override to provide handling when a key is not resolved via.
|
void |
setParameterName(String parameterName)
Set the name of the parameter to use to determine requested media types.
|
resolveMediaTypeKey, resolveMediaTypes
addMapping, getAllFileExtensions, getAllMediaTypes, getMediaTypes, lookupMediaType, resolveFileExtensions
public void setParameterName(String parameterName)
By default this is set to "format"
.
public String getParameterName()
protected String getMediaTypeKey(NativeWebRequest request)
AbstractMappingContentNegotiationStrategy
getMediaTypeKey
in class AbstractMappingContentNegotiationStrategy
null
.protected void handleMatch(String mediaTypeKey, MediaType mediaType)
AbstractMappingContentNegotiationStrategy
MappingMediaTypeFileExtensionResolver.lookupMediaType(java.lang.String)
.handleMatch
in class AbstractMappingContentNegotiationStrategy
protected MediaType handleNoMatch(NativeWebRequest request, String key) throws HttpMediaTypeNotAcceptableException
AbstractMappingContentNegotiationStrategy
MappingMediaTypeFileExtensionResolver.lookupMediaType(java.lang.String)
. Sub-classes can take further steps to
determine the media type(s). If a MediaType is returned from
this method it will be added to the cache in the base class.handleNoMatch
in class AbstractMappingContentNegotiationStrategy
HttpMediaTypeNotAcceptableException