org.springframework.web.accept

## Class AbstractMappingContentNegotiationStrategy

- java.lang.Object
- - org.springframework.web.accept.MappingMediaTypeFileExtensionResolver
  - - org.springframework.web.accept.AbstractMappingContentNegotiationStrategy

- All Implemented Interfaces:
    ContentNegotiationStrategy, MediaTypeFileExtensionResolver
  Direct Known Subclasses:
    ParameterContentNegotiationStrategy, PathExtensionContentNegotiationStrategy

      public abstract class AbstractMappingContentNegotiationStrategy
      extends MappingMediaTypeFileExtensionResolver
      implements ContentNegotiationStrategy, MediaTypeFileExtensionResolver

  A base class for ContentNegotiationStrategy types that maintain a map with keys such as "json" and media types such as "application/json".
  Since:
    3.2
  Author:
    Rossen Stoyanchev

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `AbstractMappingContentNegotiationStrategy(Map<String,MediaType> mediaTypes)` Create an instance with the given extension-to-MediaType lookup.

  - ### Method Summary

    All Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected abstract String` | `getMediaTypeKey(NativeWebRequest request)` Sub-classes must extract the key to use to look up a media type.
    `protected void` | `handleMatch(String mappingKey, MediaType mediaType)` Invoked when a matching media type is found in the lookup map.
    `protected MediaType` | `handleNoMatch(NativeWebRequest request, String mappingKey)` Invoked when no matching media type is found in the lookup map.
    `List<MediaType>` | `resolveMediaTypes(NativeWebRequest webRequest)` Resolve the given request to a list of media types.

    - ### Methods inherited from class org.springframework.web.accept.MappingMediaTypeFileExtensionResolver

      `addMapping, getAllFileExtensions, lookupMediaType, resolveFileExtensions`

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

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

    - ### Methods inherited from interface org.springframework.web.accept.MediaTypeFileExtensionResolver

      `getAllFileExtensions, resolveFileExtensions`

- - ### Constructor Detail

    - #### AbstractMappingContentNegotiationStrategy

          public AbstractMappingContentNegotiationStrategy(Map<String,MediaType> mediaTypes)

      Create an instance with the given extension-to-MediaType lookup.
      Throws:
        `IllegalArgumentException` - if a media type string cannot be parsed

  - ### Method Detail

    - #### resolveMediaTypes

          public List<MediaType> resolveMediaTypes(NativeWebRequest webRequest)

      Description copied from interface: `ContentNegotiationStrategy`
      Resolve the given request to a list of media types. The returned list is ordered by specificity first and by quality parameter second.
      Specified by:
        `resolveMediaTypes` in interface `ContentNegotiationStrategy`
      Parameters:
        `webRequest` - the current request
      Returns:
        the requested media types or an empty list, never `null`

    - #### getMediaTypeKey

          protected abstract String getMediaTypeKey(NativeWebRequest request)

      Sub-classes must extract the key to use to look up a media type.
      Returns:
        the lookup key or `null` if the key cannot be derived

    - #### handleMatch

          protected void handleMatch(String mappingKey,
                                     MediaType mediaType)

      Invoked when a matching media type is found in the lookup map.

    - #### handleNoMatch

          protected MediaType handleNoMatch(NativeWebRequest request,
                                            String mappingKey)

      Invoked when no matching media type is found in the lookup map. Sub-classes can take further steps to determine the media type.