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 Summary
Fields inherited from class AbstractDecoder
logger -
Constructor Summary
ConstructorsConstructorDescriptionConstruct 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 Summary
Modifier 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 AbstractDataBufferDecoder
decodeDataBuffer, decodeToMono, getMaxInMemorySize, setMaxInMemorySizeMethods inherited from class AbstractDecoder
getDecodableMimeTypes, getLogger, setLoggerMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Decoder
getDecodableMimeTypes
-
Constructor Details
-
GsonDecoder
public GsonDecoder()Construct a new decoder using a defaultGsoninstance and the"application/json"and"application/*+json"MIME types. -
GsonDecoder
Construct a new decoder using the givenGsoninstance and the provided MIME types.- Parameters:
gson- the gson instance to usemimeTypes- the mime types the decoder should support
-
-
Method Details
-
canDecode
Description copied from interface:DecoderWhether the decoder supports the given target element type and the MIME type of the source stream.- Specified by:
canDecodein interfaceDecoder<Object>- Overrides:
canDecodein classAbstractDecoder<Object>- 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
public 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 interfaceDecoder<Object>- Overrides:
decodein classAbstractDataBufferDecoder<Object>- Parameters:
inputStream- theDataBufferinput stream to decodeelementType- the expected type of elements in the output stream; this type must have been previously passed to theDecoder.canDecode(ResolvableType, MimeType)method and it must have returnedtrue.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
-
decode
public @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- theDataBufferto decodetargetType- the expected output typemimeType- the MIME type associated with the datahints- additional information about how to do decode- Returns:
- the decoded value, possibly
null - Throws:
DecodingException
-