Class GsonDecoder
- All Implemented Interfaces:
org.springframework.core.codec.Decoder<Object>
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 org.springframework.core.codec.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, org.springframework.util.MimeType... mimeTypes) Construct a new decoder using the givenGsoninstance and the provided MIME types. -
Method Summary
Modifier and TypeMethodDescriptionbooleancanDecode(org.springframework.core.ResolvableType elementType, @Nullable org.springframework.util.MimeType mimeType) reactor.core.publisher.Flux<Object> decode(Publisher<org.springframework.core.io.buffer.DataBuffer> inputStream, org.springframework.core.ResolvableType elementType, @Nullable org.springframework.util.MimeType mimeType, @Nullable Map<String, Object> hints) decode(org.springframework.core.io.buffer.DataBuffer buffer, org.springframework.core.ResolvableType targetType, @Nullable org.springframework.util.MimeType mimeType, @Nullable Map<String, Object> hints) Methods inherited from class org.springframework.core.codec.AbstractDataBufferDecoder
decodeDataBuffer, decodeToMono, getMaxInMemorySize, setMaxInMemorySizeMethods inherited from class org.springframework.core.codec.AbstractDecoder
getDecodableMimeTypes, getLogger, setLoggerMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.core.codec.Decoder
getDecodableMimeTypes
-
Constructor Details
-
GsonDecoder
public GsonDecoder()Construct a new decoder using a defaultGsoninstance and the"application/json"and"application/*+json"MIME types. -
GsonDecoder
public GsonDecoder(com.google.gson.Gson gson, org.springframework.util.MimeType... mimeTypes) 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
public boolean canDecode(org.springframework.core.ResolvableType elementType, @Nullable org.springframework.util.MimeType mimeType) -
decode
-
decode
public @Nullable Object decode(org.springframework.core.io.buffer.DataBuffer buffer, org.springframework.core.ResolvableType targetType, @Nullable org.springframework.util.MimeType mimeType, @Nullable Map<String, Object> hints) throws org.springframework.core.codec.DecodingException- Throws:
org.springframework.core.codec.DecodingException
-