public abstract class AbstractJackson2Encoder extends Jackson2CodecSupport implements HttpMessageEncoder<Object>
Flux
elements are collected into a List
before serialization for
performance reason.JSON_VIEW_HINT
Modifier | Constructor and Description |
---|---|
protected |
AbstractJackson2Encoder(ObjectMapper mapper,
org.springframework.util.MimeType... mimeTypes)
Constructor with a Jackson
ObjectMapper to use. |
Modifier and Type | Method and Description |
---|---|
boolean |
canEncode(org.springframework.core.ResolvableType elementType,
org.springframework.util.MimeType mimeType) |
protected ObjectWriter |
customizeWriter(ObjectWriter writer,
org.springframework.util.MimeType mimeType,
org.springframework.core.ResolvableType elementType,
Map<String,Object> hints) |
reactor.core.publisher.Flux<org.springframework.core.io.buffer.DataBuffer> |
encode(org.reactivestreams.Publisher<?> inputStream,
org.springframework.core.io.buffer.DataBufferFactory bufferFactory,
org.springframework.core.ResolvableType elementType,
org.springframework.util.MimeType mimeType,
Map<String,Object> hints) |
protected <A extends Annotation> |
getAnnotation(org.springframework.core.MethodParameter parameter,
Class<A> annotType) |
List<org.springframework.util.MimeType> |
getEncodableMimeTypes() |
Map<String,Object> |
getEncodeHints(org.springframework.core.ResolvableType actualType,
org.springframework.core.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(org.springframework.util.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, org.springframework.util.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(org.springframework.core.ResolvableType elementType, @Nullable org.springframework.util.MimeType mimeType)
canEncode
in interface org.springframework.core.codec.Encoder<Object>
public reactor.core.publisher.Flux<org.springframework.core.io.buffer.DataBuffer> encode(org.reactivestreams.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)
encode
in interface org.springframework.core.codec.Encoder<Object>
protected ObjectWriter customizeWriter(ObjectWriter writer, @Nullable org.springframework.util.MimeType mimeType, org.springframework.core.ResolvableType elementType, @Nullable Map<String,Object> hints)
protected JsonEncoding getJsonEncoding(@Nullable org.springframework.util.MimeType mimeType)
mimeType
- the mime type as requested by the callernull
)public List<org.springframework.util.MimeType> getEncodableMimeTypes()
getEncodableMimeTypes
in interface org.springframework.core.codec.Encoder<Object>
public List<MediaType> getStreamingMediaTypes()
HttpMessageEncoder
getStreamingMediaTypes
in interface HttpMessageEncoder<Object>
public Map<String,Object> getEncodeHints(@Nullable org.springframework.core.ResolvableType actualType, org.springframework.core.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(org.springframework.core.MethodParameter parameter, Class<A> annotType)
getAnnotation
in class Jackson2CodecSupport