Class GsonEncoder
java.lang.Object
org.springframework.core.codec.AbstractEncoder<Object>
org.springframework.http.codec.json.GsonEncoder
- All Implemented Interfaces:
org.springframework.core.codec.Encoder<Object>, HttpMessageEncoder<Object>
public class GsonEncoder
extends org.springframework.core.codec.AbstractEncoder<Object>
implements HttpMessageEncoder<Object>
Encode from an
Object stream to a byte stream of JSON objects using
Google Gson.- Since:
- 7.0
- Author:
- Brian Clozel
-
Field Summary
Fields inherited from class org.springframework.core.codec.AbstractEncoder
logger -
Constructor Summary
ConstructorsConstructorDescriptionConstruct a new encoder using a defaultGsoninstance and the"application/json"and"application/*+json"MIME types.GsonEncoder(com.google.gson.Gson gson, org.springframework.util.MimeType... mimeTypes) Construct a new encoder using the givenGsoninstance and the provided MIME types. -
Method Summary
Modifier and TypeMethodDescriptionbooleancanEncode(org.springframework.core.ResolvableType elementType, @Nullable org.springframework.util.MimeType mimeType) reactor.core.publisher.Flux<org.springframework.core.io.buffer.DataBuffer> encode(Publisher<?> inputStream, org.springframework.core.io.buffer.DataBufferFactory bufferFactory, org.springframework.core.ResolvableType elementType, @Nullable org.springframework.util.MimeType mimeType, @Nullable Map<String, Object> hints) org.springframework.core.io.buffer.DataBufferencodeValue(Object value, org.springframework.core.io.buffer.DataBufferFactory bufferFactory, org.springframework.core.ResolvableType valueType, @Nullable org.springframework.util.MimeType mimeType, @Nullable Map<String, Object> hints) Return "streaming" media types for which flushing should be performed automatically vs at the end of the input stream.protected booleanisStreamingMediaType(@Nullable org.springframework.util.MimeType mimeType) Return the separator to use for the given mime type.voidsetStreamingMediaTypes(List<MediaType> mediaTypes) Configure "streaming" media types for which flushing should be performed automatically vs at the end of the stream.Methods inherited from class org.springframework.core.codec.AbstractEncoder
getEncodableMimeTypes, getLogger, setLoggerMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.core.codec.Encoder
getEncodableMimeTypes, getEncodableMimeTypesMethods inherited from interface HttpMessageEncoder
getEncodeHints
-
Constructor Details
-
GsonEncoder
public GsonEncoder()Construct a new encoder using a defaultGsoninstance and the"application/json"and"application/*+json"MIME types. The"application/x-ndjson"is configured for streaming. -
GsonEncoder
public GsonEncoder(com.google.gson.Gson gson, org.springframework.util.MimeType... mimeTypes) Construct a new encoder using the givenGsoninstance and the provided MIME types. UsesetStreamingMediaTypes(List)for configuring streaming media types.- Parameters:
gson- the gson instance to usemimeTypes- the mime types the decoder should support
-
-
Method Details
-
setStreamingMediaTypes
-
getStreamingMediaTypes
Description copied from interface:HttpMessageEncoderReturn "streaming" media types for which flushing should be performed automatically vs at the end of the input stream.- Specified by:
getStreamingMediaTypesin interfaceHttpMessageEncoder<Object>
-
canEncode
public boolean canEncode(org.springframework.core.ResolvableType elementType, @Nullable org.springframework.util.MimeType mimeType) -
encode
public reactor.core.publisher.Flux<org.springframework.core.io.buffer.DataBuffer> encode(Publisher<?> inputStream, org.springframework.core.io.buffer.DataBufferFactory bufferFactory, org.springframework.core.ResolvableType elementType, @Nullable org.springframework.util.MimeType mimeType, @Nullable Map<String, Object> hints) - Specified by:
encodein interfaceorg.springframework.core.codec.Encoder<Object>
-
encodeValue
public org.springframework.core.io.buffer.DataBuffer encodeValue(Object value, org.springframework.core.io.buffer.DataBufferFactory bufferFactory, org.springframework.core.ResolvableType valueType, @Nullable org.springframework.util.MimeType mimeType, @Nullable Map<String, Object> hints) - Specified by:
encodeValuein interfaceorg.springframework.core.codec.Encoder<Object>
-
isStreamingMediaType
-