public abstract class AbstractJackson2Encoder extends Jackson2CodecSupport implements HttpMessageEncoder<Object>
Flux
elements are collected into a List
before serialization for
performance reason.JSON_VIEW_HINT, logger
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,
Map<String,Object> hints) |
reactor.core.publisher.Flux<DataBuffer> |
encode(org.reactivestreams.Publisher<?> inputStream,
DataBufferFactory bufferFactory,
ResolvableType elementType,
MimeType mimeType,
Map<String,Object> hints)
Encode a stream of Objects of type
T into a DataBuffer
output stream. |
DataBuffer |
encodeValue(Object value,
DataBufferFactory bufferFactory,
ResolvableType valueType,
MimeType mimeType,
Map<String,Object> hints) |
protected <A extends Annotation> |
getAnnotation(MethodParameter parameter,
Class<A> annotType) |
List<MimeType> |
getEncodableMimeTypes()
Return the list of mime types this encoder supports.
|
Map<String,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.
|
List<MediaType> |
getStreamingMediaTypes()
Return "streaming" media types for which flushing should be performed
automatically vs at the end of the input stream.
|
void |
setStreamingMediaTypes(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
protected AbstractJackson2Encoder(ObjectMapper mapper, MimeType... mimeTypes)
ObjectMapper
to use.public void setStreamingMediaTypes(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 Map<String,Object> hints)
Encoder
T
into a DataBuffer
output stream.encode
in interface Encoder<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 encodepublic DataBuffer encodeValue(Object value, DataBufferFactory bufferFactory, ResolvableType valueType, @Nullable MimeType mimeType, @Nullable Map<String,Object> hints)
protected ObjectWriter customizeWriter(ObjectWriter writer, @Nullable MimeType mimeType, ResolvableType elementType, @Nullable Map<String,Object> hints)
protected JsonEncoding getJsonEncoding(@Nullable MimeType mimeType)
mimeType
- the mime type as requested by the callernull
)public List<MimeType> getEncodableMimeTypes()
Encoder
getEncodableMimeTypes
in interface Encoder<Object>
public List<MediaType> getStreamingMediaTypes()
HttpMessageEncoder
getStreamingMediaTypes
in interface HttpMessageEncoder<Object>
public Map<String,Object> getEncodeHints(@Nullable ResolvableType actualType, ResolvableType elementType, @Nullable MediaType mediaType, ServerHttpRequest request, ServerHttpResponse response)
HttpMessageEncoder
getEncodeHints
in interface HttpMessageEncoder<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 Annotation> A getAnnotation(MethodParameter parameter, Class<A> annotType)
getAnnotation
in class Jackson2CodecSupport