public abstract class AbstractJackson2Encoder extends Jackson2CodecSupport implements HttpMessageEncoder<java.lang.Object>
Flux
elements are collected into a List
before serialization for
performance reason.JSON_VIEW_HINT
Modifier | Constructor and Description |
---|---|
protected |
AbstractJackson2Encoder(ObjectMapper mapper,
MimeType... mimeTypes)
Constructor with a Jackson
ObjectMapper to use. |
Modifier and Type | Method and Description |
---|---|
boolean |
canEncode(ResolvableType elementType,
MimeType mimeType)
Whether the encoder supports the given source element type and the MIME
type for the output stream.
|
protected ObjectWriter |
customizeWriter(ObjectWriter writer,
MimeType mimeType,
ResolvableType elementType,
java.util.Map<java.lang.String,java.lang.Object> hints) |
reactor.core.publisher.Flux<DataBuffer> |
encode(org.reactivestreams.Publisher<?> inputStream,
DataBufferFactory bufferFactory,
ResolvableType elementType,
MimeType mimeType,
java.util.Map<java.lang.String,java.lang.Object> hints)
Encode a stream of Objects of type
T into a DataBuffer
output stream. |
protected <A extends java.lang.annotation.Annotation> |
getAnnotation(MethodParameter parameter,
java.lang.Class<A> annotType) |
java.util.List<MimeType> |
getEncodableMimeTypes()
Return the list of mime types this encoder supports.
|
java.util.Map<java.lang.String,java.lang.Object> |
getEncodeHints(ResolvableType actualType,
ResolvableType elementType,
MediaType mediaType,
ServerHttpRequest request,
ServerHttpResponse response)
Get decoding hints based on the server request or annotations on the
target controller method parameter.
|
protected JsonEncoding |
getJsonEncoding(MimeType mimeType)
Determine the JSON encoding to use for the given mime type.
|
java.util.List<MediaType> |
getStreamingMediaTypes()
Return "streaming" media types for which flushing should be performed
automatically vs at the end of the input stream.
|
void |
setStreamingMediaTypes(java.util.List<MediaType> mediaTypes)
Configure "streaming" media types for which flushing should be performed
automatically vs at the end of the stream.
|
getHints, getJavaType, getMimeTypes, getObjectMapper, getParameter, supportsMimeType
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getContentLength
protected AbstractJackson2Encoder(ObjectMapper mapper, MimeType... mimeTypes)
ObjectMapper
to use.public void setStreamingMediaTypes(java.util.List<MediaType> mediaTypes)
By default this is set to MediaType.APPLICATION_STREAM_JSON
.
mediaTypes
- one or more media types to add to the listHttpMessageEncoder.getStreamingMediaTypes()
public boolean canEncode(ResolvableType elementType, @Nullable MimeType mimeType)
Encoder
public reactor.core.publisher.Flux<DataBuffer> encode(org.reactivestreams.Publisher<?> inputStream, DataBufferFactory bufferFactory, ResolvableType elementType, @Nullable MimeType mimeType, @Nullable java.util.Map<java.lang.String,java.lang.Object> hints)
Encoder
T
into a DataBuffer
output stream.encode
in interface Encoder<java.lang.Object>
inputStream
- the input stream of Objects to encode. If the input should be
encoded as a single value rather than as a stream of elements, an instance of
Mono
should be used.bufferFactory
- for creating output stream DataBuffer
'selementType
- the expected type of elements in the input stream;
this type must have been previously passed to the Encoder.canEncode(org.springframework.core.ResolvableType, org.springframework.util.MimeType)
method and it must have returned true
.mimeType
- the MIME type for the output stream (optional)hints
- additional information about how to do encodeprotected ObjectWriter customizeWriter(ObjectWriter writer, @Nullable MimeType mimeType, ResolvableType elementType, @Nullable java.util.Map<java.lang.String,java.lang.Object> hints)
protected JsonEncoding getJsonEncoding(@Nullable MimeType mimeType)
mimeType
- the mime type as requested by the callernull
)public java.util.List<MimeType> getEncodableMimeTypes()
Encoder
getEncodableMimeTypes
in interface Encoder<java.lang.Object>
public java.util.List<MediaType> getStreamingMediaTypes()
HttpMessageEncoder
getStreamingMediaTypes
in interface HttpMessageEncoder<java.lang.Object>
public java.util.Map<java.lang.String,java.lang.Object> getEncodeHints(@Nullable ResolvableType actualType, ResolvableType elementType, @Nullable MediaType mediaType, ServerHttpRequest request, ServerHttpResponse response)
HttpMessageEncoder
getEncodeHints
in interface HttpMessageEncoder<java.lang.Object>
actualType
- the actual source type to encode, possibly a reactive
wrapper and sourced from MethodParameter
,
i.e. providing access to method annotations.elementType
- the element type within Flux/Mono
that we're
trying to encode.request
- the current requestresponse
- the current responseprotected <A extends java.lang.annotation.Annotation> A getAnnotation(MethodParameter parameter, java.lang.Class<A> annotType)
getAnnotation
in class Jackson2CodecSupport