Package org.springframework.core.codec
Interface Decoder<T>
- Type Parameters:
T- the type of elements in the output stream
- All Known Subinterfaces:
HttpMessageDecoder<T>
- All Known Implementing Classes:
AbstractDataBufferDecoder,AbstractDecoder,AbstractJackson2Decoder,ByteArrayDecoder,ByteBufferDecoder,DataBufferDecoder,Jackson2CborDecoder,Jackson2JsonDecoder,Jackson2SmileDecoder,Jaxb2XmlDecoder,ProtobufDecoder,ResourceDecoder,StringDecoder,XmlEventDecoder
public interface Decoder<T>
Strategy for decoding aDataBufferinput stream into an output stream of elements of type<T>.- Since:
- 5.0
- Author:
- Sebastien Deleuze, Rossen Stoyanchev
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description booleancanDecode(ResolvableType elementType, MimeType mimeType)Whether the decoder supports the given target element type and the MIME type of the source stream.reactor.core.publisher.Flux<T>decode(org.reactivestreams.Publisher<DataBuffer> inputStream, ResolvableType elementType, MimeType mimeType, Map<String,Object> hints)Decode aDataBufferinput stream into a Flux ofT.default Tdecode(DataBuffer buffer, ResolvableType targetType, MimeType mimeType, Map<String,Object> hints)Decode a data buffer to an Object of type T.reactor.core.publisher.Mono<T>decodeToMono(org.reactivestreams.Publisher<DataBuffer> inputStream, ResolvableType elementType, MimeType mimeType, Map<String,Object> hints)Decode aDataBufferinput stream into a Mono ofT.List<MimeType>getDecodableMimeTypes()Return the list of MIME types this decoder supports.
Method Detail
canDecode
boolean canDecode(ResolvableType elementType, @Nullable MimeType mimeType)
Whether the decoder supports the given target element type and the MIME type of the source stream.- Parameters:
elementType- the target element type for the output streammimeType- the mime type associated with the stream to decode (can benullif not specified)- Returns:
trueif supported,falseotherwise
decode
reactor.core.publisher.Flux<T> decode(org.reactivestreams.Publisher<DataBuffer> inputStream, ResolvableType elementType, @Nullable MimeType mimeType, @Nullable Map<String,Object> hints)
Decode aDataBufferinput stream into a Flux ofT.- Parameters:
inputStream- theDataBufferinput stream to decodeelementType- the expected type of elements in the output stream; this type must have been previously passed to thecanDecode(org.springframework.core.ResolvableType, org.springframework.util.MimeType)method and it must have returnedtrue.mimeType- the MIME type associated with the input stream (optional)hints- additional information about how to do encode- Returns:
- the output stream with decoded elements
decodeToMono
reactor.core.publisher.Mono<T> decodeToMono(org.reactivestreams.Publisher<DataBuffer> inputStream, ResolvableType elementType, @Nullable MimeType mimeType, @Nullable Map<String,Object> hints)
Decode aDataBufferinput stream into a Mono ofT.- Parameters:
inputStream- theDataBufferinput stream to decodeelementType- the expected type of elements in the output stream; this type must have been previously passed to thecanDecode(org.springframework.core.ResolvableType, org.springframework.util.MimeType)method and it must have returnedtrue.mimeType- the MIME type associated with the input stream (optional)hints- additional information about how to do encode- Returns:
- the output stream with the decoded element
decode
@Nullable default T decode(DataBuffer buffer, ResolvableType targetType, @Nullable MimeType mimeType, @Nullable Map<String,Object> hints) throws DecodingException
Decode a data buffer to an Object of type T. This is useful for scenarios, that distinct messages (or events) are decoded and handled individually, in fully aggregated form.- Parameters:
buffer- theDataBufferto decodetargetType- the expected output typemimeType- the MIME type associated with the datahints- additional information about how to do encode- Returns:
- the decoded value, possibly
null - Throws:
DecodingException- Since:
- 5.2
getDecodableMimeTypes
List<MimeType> getDecodableMimeTypes()
Return the list of MIME types this decoder supports.