MIME types by Class for Encoder, Decoder, HttpMessageReader|Writer
Closes gh-26212
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.core.codec;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
@@ -59,7 +60,7 @@ public interface Decoder<T> {
|
||||
* this type must have been previously passed to the {@link #canDecode}
|
||||
* method and it must have returned {@code true}.
|
||||
* @param mimeType the MIME type associated with the input stream (optional)
|
||||
* @param hints additional information about how to do encode
|
||||
* @param hints additional information about how to do decode
|
||||
* @return the output stream with decoded elements
|
||||
*/
|
||||
Flux<T> decode(Publisher<DataBuffer> inputStream, ResolvableType elementType,
|
||||
@@ -72,7 +73,7 @@ public interface Decoder<T> {
|
||||
* this type must have been previously passed to the {@link #canDecode}
|
||||
* method and it must have returned {@code true}.
|
||||
* @param mimeType the MIME type associated with the input stream (optional)
|
||||
* @param hints additional information about how to do encode
|
||||
* @param hints additional information about how to do decode
|
||||
* @return the output stream with the decoded element
|
||||
*/
|
||||
Mono<T> decodeToMono(Publisher<DataBuffer> inputStream, ResolvableType elementType,
|
||||
@@ -85,7 +86,7 @@ public interface Decoder<T> {
|
||||
* @param buffer the {@code DataBuffer} to decode
|
||||
* @param targetType the expected output type
|
||||
* @param mimeType the MIME type associated with the data
|
||||
* @param hints additional information about how to do encode
|
||||
* @param hints additional information about how to do decode
|
||||
* @return the decoded value, possibly {@code null}
|
||||
* @since 5.2
|
||||
*/
|
||||
@@ -111,8 +112,27 @@ public interface Decoder<T> {
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the list of MIME types this decoder supports.
|
||||
* Return the list of MIME types supported by this Decoder. The list may not
|
||||
* apply to every possible target element type and calls to this method
|
||||
* should typically be guarded via {@link #canDecode(ResolvableType, MimeType)
|
||||
* canDecode(elementType, null)}. The list may also exclude MIME types
|
||||
* supported only for a specific element type. Alternatively, use
|
||||
* {@link #getDecodableMimeTypes(ResolvableType)} for a more precise list.
|
||||
* @return the list of supported MIME types
|
||||
*/
|
||||
List<MimeType> getDecodableMimeTypes();
|
||||
|
||||
/**
|
||||
* Return the list of MIME types supported by this Decoder for the given type
|
||||
* of element. This list may differ from {@link #getDecodableMimeTypes()}
|
||||
* if the Decoder doesn't support the given element type or if it supports
|
||||
* it only for a subset of MIME types.
|
||||
* @param targetType the type of element to check for decoding
|
||||
* @return the list of MIME types supported for the given target type
|
||||
* @since 5.3.4
|
||||
*/
|
||||
default List<MimeType> getDecodableMimeTypes(ResolvableType targetType) {
|
||||
return (canDecode(targetType, null) ? getDecodableMimeTypes() : Collections.emptyList());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.core.codec;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -90,8 +91,27 @@ public interface Encoder<T> {
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the list of mime types this encoder supports.
|
||||
* Return the list of MIME types supported by this Encoder. The list may not
|
||||
* apply to every possible target element type and calls to this method should
|
||||
* typically be guarded via {@link #canEncode(ResolvableType, MimeType)
|
||||
* canEncode(elementType, null)}. The list may also exclude MIME types
|
||||
* supported only for a specific element type. Alternatively, use
|
||||
* {@link #getEncodableMimeTypes(ResolvableType)} for a more precise list.
|
||||
* @return the list of supported MIME types
|
||||
*/
|
||||
List<MimeType> getEncodableMimeTypes();
|
||||
|
||||
/**
|
||||
* Return the list of MIME types supported by this Encoder for the given type
|
||||
* of element. This list may differ from the {@link #getEncodableMimeTypes()}
|
||||
* if the Encoder doesn't support the element type or if it supports it only
|
||||
* for a subset of MIME types.
|
||||
* @param elementType the type of element to check for encoding
|
||||
* @return the list of MIME types supported for the given element type
|
||||
* @since 5.3.4
|
||||
*/
|
||||
default List<MimeType> getEncodableMimeTypes(ResolvableType elementType) {
|
||||
return (canEncode(elementType, null) ? getEncodableMimeTypes() : Collections.emptyList());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user