org.springframework.web.accept

## Class MappingMediaTypeFileExtensionResolver

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

All Implemented Interfaces:
  MediaTypeFileExtensionResolver

Direct Known Subclasses:
  AbstractMappingContentNegotiationStrategy

    public class MappingMediaTypeFileExtensionResolver
    extends Object
    implements MediaTypeFileExtensionResolver

An implementation of `MediaTypeFileExtensionResolver` that maintains a lookup from extension to MediaType.

Since:
  3.2
Author:
  Rossen Stoyanchev

### Constructor Summary

Constructors
Constructor and Description
`MappingMediaTypeFileExtensionResolver(Map<String,MediaType> mediaTypes)` Create an instance with the given mappings between extensions and media types.

### Method Summary

Methods
`protected void` `addMapping(String extension, MediaType mediaType)` Map a MediaType to an extension or ignore if the extensions is already mapped.
`List<String>` `getAllFileExtensions()` Return all known file extensions.
`protected MediaType` `lookupMediaType(String extension)` Return the MediaType mapped to the given extension.
`List<String>` `resolveFileExtensions(MediaType mediaType)` Find the file extensions mapped to the given MediaType.

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

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

### Constructor Detail

#### MappingMediaTypeFileExtensionResolver

    public MappingMediaTypeFileExtensionResolver(Map<String,MediaType> mediaTypes)

Create an instance with the given mappings between extensions and media types.

Throws:
  `IllegalArgumentException` - if a media type string cannot be parsed

### Method Detail

#### resolveFileExtensions

    public List<String> resolveFileExtensions(MediaType mediaType)

Find the file extensions mapped to the given MediaType.

Specified by:
  `resolveFileExtensions` in interface `MediaTypeFileExtensionResolver`
Parameters:
  `mediaType` - the media type to resolve
Returns:
  0 or more extensions, never `null`

#### getAllFileExtensions

    public List<String> getAllFileExtensions()

Description copied from interface: `MediaTypeFileExtensionResolver`
Return all known file extensions.

Specified by:
  `getAllFileExtensions` in interface `MediaTypeFileExtensionResolver`
Returns:
  a list of extensions or an empty list, never `null`

#### lookupMediaType

    protected MediaType lookupMediaType(String extension)

Return the MediaType mapped to the given extension.

Returns:
  a MediaType for the key or `null`

#### addMapping

    protected void addMapping(String extension,
                  MediaType mediaType)

Map a MediaType to an extension or ignore if the extensions is already mapped.