Class GsonDecoder
java.lang.Object
org.springframework.core.codec.AbstractDecoder<Object>
org.springframework.core.codec.AbstractDataBufferDecoder<Object>
org.springframework.http.codec.json.GsonDecoder
Decoder that reads a byte stream into JSON and converts it to Objects with
Google Gson.
Flux<*> target types are not available because non-blocking parsing is not supported,
so this decoder targets only Mono<*> types. Attempting to decode to a Flux<*> will
result in a UnsupportedOperationException being thrown at runtime.
- Since:
- 7.0
- Author:
- Brian Clozel
- 
Field SummaryFields inherited from class AbstractDecoderlogger
- 
Constructor SummaryConstructorsConstructorDescriptionConstruct a new decoder using a defaultGsoninstance and the"application/json"and"application/*+json"MIME types.GsonDecoder(com.google.gson.Gson gson, MimeType... mimeTypes) Construct a new decoder using the givenGsoninstance and the provided MIME types.
- 
Method SummaryModifier and TypeMethodDescriptionbooleancanDecode(ResolvableType elementType, @Nullable MimeType mimeType) Whether the decoder supports the given target element type and the MIME type of the source stream.reactor.core.publisher.Flux<Object> decode(Publisher<DataBuffer> inputStream, ResolvableType elementType, @Nullable MimeType mimeType, @Nullable Map<String, Object> hints) Decode aDataBufferinput stream into a Flux ofT.decode(DataBuffer buffer, ResolvableType targetType, @Nullable MimeType mimeType, @Nullable Map<String, Object> hints) Decode a data buffer to an Object of type T.Methods inherited from class AbstractDataBufferDecoderdecodeDataBuffer, decodeToMono, getMaxInMemorySize, setMaxInMemorySizeMethods inherited from class AbstractDecodergetDecodableMimeTypes, getLogger, setLoggerMethods inherited from class Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface DecodergetDecodableMimeTypes
- 
Constructor Details- 
GsonDecoderpublic GsonDecoder()Construct a new decoder using a defaultGsoninstance and the"application/json"and"application/*+json"MIME types.
- 
GsonDecoderConstruct a new decoder using the givenGsoninstance and the provided MIME types.- Parameters:
- gson- the gson instance to use
- mimeTypes- the mime types the decoder should support
 
 
- 
- 
Method Details- 
canDecodeDescription copied from interface:DecoderWhether the decoder supports the given target element type and the MIME type of the source stream.- Specified by:
- canDecodein interface- Decoder<Object>
- Overrides:
- canDecodein class- AbstractDecoder<Object>
- Parameters:
- elementType- the target element type for the output stream
- mimeType- the mime type associated with the stream to decode (can be- nullif not specified)
- Returns:
- trueif supported,- falseotherwise
 
- 
decodepublic reactor.core.publisher.Flux<Object> decode(Publisher<DataBuffer> inputStream, ResolvableType elementType, @Nullable MimeType mimeType, @Nullable Map<String, Object> hints) Description copied from interface:DecoderDecode aDataBufferinput stream into a Flux ofT.- Specified by:
- decodein interface- Decoder<Object>
- Overrides:
- decodein class- AbstractDataBufferDecoder<Object>
- Parameters:
- inputStream- the- DataBufferinput stream to decode
- elementType- the expected type of elements in the output stream; this type must have been previously passed to the- Decoder.canDecode(ResolvableType, MimeType)method and it must have returned- true.
- mimeType- the MIME type associated with the input stream (optional)
- hints- additional information about how to do decode
- Returns:
- the output stream with decoded elements
 
- 
decodepublic @Nullable Object decode(DataBuffer buffer, ResolvableType targetType, @Nullable MimeType mimeType, @Nullable Map<String, Object> hints) throws DecodingExceptionDescription copied from interface:DecoderDecode 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- the- DataBufferto decode
- targetType- the expected output type
- mimeType- the MIME type associated with the data
- hints- additional information about how to do decode
- Returns:
- the decoded value, possibly null
- Throws:
- DecodingException
 
 
-