Class GsonDecoder

java.lang.Object
org.springframework.core.codec.AbstractDecoder<Object>
org.springframework.core.codec.AbstractDataBufferDecoder<Object>
org.springframework.http.codec.json.GsonDecoder
All Implemented Interfaces:
org.springframework.core.codec.Decoder<Object>

public class GsonDecoder extends org.springframework.core.codec.AbstractDataBufferDecoder<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

    Constructors
    Constructor
    Description
    Construct a new decoder using a default Gson instance 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 given Gson instance and the provided MIME types.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    canDecode(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, setMaxInMemorySize

    Methods inherited from class org.springframework.core.codec.AbstractDecoder

    getDecodableMimeTypes, getLogger, setLogger

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.springframework.core.codec.Decoder

    getDecodableMimeTypes
  • Constructor Details

    • GsonDecoder

      public GsonDecoder()
      Construct a new decoder using a default Gson instance 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 given Gson instance and the provided MIME types.
      Parameters:
      gson - the gson instance to use
      mimeTypes - the mime types the decoder should support
  • Method Details

    • canDecode

      public boolean canDecode(org.springframework.core.ResolvableType elementType, @Nullable org.springframework.util.MimeType mimeType)
      Specified by:
      canDecode in interface org.springframework.core.codec.Decoder<Object>
      Overrides:
      canDecode in class org.springframework.core.codec.AbstractDecoder<Object>
    • decode

      public 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)
      Specified by:
      decode in interface org.springframework.core.codec.Decoder<Object>
      Overrides:
      decode in class org.springframework.core.codec.AbstractDataBufferDecoder<Object>
    • 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