Class AbstractJacksonEncoder<T extends tools.jackson.databind.ObjectMapper>
java.lang.Object
org.springframework.http.codec.JacksonCodecSupport<T>
org.springframework.http.codec.AbstractJacksonEncoder<T>
- Type Parameters:
T- the type ofObjectMapper
- All Implemented Interfaces:
org.springframework.core.codec.Encoder<Object>, HttpMessageEncoder<Object>
- Direct Known Subclasses:
JacksonCborEncoder, JacksonJsonEncoder, JacksonSmileEncoder
public abstract class AbstractJacksonEncoder<T extends tools.jackson.databind.ObjectMapper>
extends JacksonCodecSupport<T>
implements HttpMessageEncoder<Object>
Base class providing support methods for Jackson 3.x encoding. For non-streaming use
cases,
Flux elements are collected into a List before serialization for
performance reasons.- Since:
- 7.0
- Author:
- Sebastien Deleuze
-
Field Summary
Fields inherited from class JacksonCodecSupport
FILTER_PROVIDER_HINT, JSON_VIEW_HINT, logger, mapperRegistrations -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractJacksonEncoder(tools.jackson.databind.cfg.MapperBuilder<T, ?> builder, org.springframework.util.MimeType... mimeTypes) Construct a new instance with the providedbuildercustomized with theJacksonModules found byMapperBuilder.findModules(ClassLoader)andMimeTypes.protectedAbstractJacksonEncoder(T mapper, org.springframework.util.MimeType... mimeTypes) Construct a new instance with the providedObjectMapperandMimeTypes. -
Method Summary
Modifier and TypeMethodDescriptionbooleancanEncode(org.springframework.core.ResolvableType elementType, @Nullable org.springframework.util.MimeType mimeType) protected tools.jackson.databind.ObjectWritercustomizeWriter(tools.jackson.databind.ObjectWriter writer, @Nullable org.springframework.util.MimeType mimeType, org.springframework.core.ResolvableType elementType, @Nullable Map<String, Object> hints) Subclasses can use this method to customize theObjectWriterused for writing values.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) protected <A extends Annotation>
@Nullable AgetAnnotation(org.springframework.core.MethodParameter parameter, Class<A> annotType) List<org.springframework.util.MimeType> List<org.springframework.util.MimeType> getEncodableMimeTypes(org.springframework.core.ResolvableType elementType) getEncodeHints(@Nullable org.springframework.core.ResolvableType actualType, org.springframework.core.ResolvableType elementType, @Nullable MediaType mediaType, ServerHttpRequest request, ServerHttpResponse response) Get decoding hints based on the server request or annotations on the target controller method parameter.protected tools.jackson.core.JsonEncodinggetJsonEncoding(@Nullable org.springframework.util.MimeType mimeType) Determine the JSON encoding to use for the given mime type.Return "streaming" media types for which flushing should be performed automatically vs at the end of the input stream.protected byte @Nullable []getStreamingMediaTypeSeparator(@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 JacksonCodecSupport
getHints, getJavaType, getMapper, getMapperRegistrations, getMappersForType, getMediaTypesForProblemDetail, getMimeTypes, getMimeTypes, getParameter, registerMappersForType, selectMapper, supportsMimeType
-
Constructor Details
-
AbstractJacksonEncoder
protected AbstractJacksonEncoder(tools.jackson.databind.cfg.MapperBuilder<T, ?> builder, org.springframework.util.MimeType... mimeTypes) Construct a new instance with the providedbuildercustomized with theJacksonModules found byMapperBuilder.findModules(ClassLoader)andMimeTypes. -
AbstractJacksonEncoder
Construct a new instance with the providedObjectMapperandMimeTypes.
-
-
Method Details
-
setStreamingMediaTypes
-
canEncode
-
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<T extends tools.jackson.databind.ObjectMapper>
-
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<T extends tools.jackson.databind.ObjectMapper>
-
customizeWriter
protected tools.jackson.databind.ObjectWriter customizeWriter(tools.jackson.databind.ObjectWriter writer, @Nullable org.springframework.util.MimeType mimeType, org.springframework.core.ResolvableType elementType, @Nullable Map<String, Object> hints) Subclasses can use this method to customize theObjectWriterused for writing values.- Parameters:
writer- the writer instance to customizemimeType- the selected MIME typeelementType- the type of element values to writehints- a map with serialization hints; the Reactor Context, when available, may be accessed under the keyContextView.class.getName()- Returns:
- the customized
ObjectWriterto use
-
getStreamingMediaTypeSeparator
-
getJsonEncoding
protected tools.jackson.core.JsonEncoding getJsonEncoding(@Nullable org.springframework.util.MimeType mimeType) Determine the JSON encoding to use for the given mime type.- Parameters:
mimeType- the mime type as requested by the caller- Returns:
- the JSON encoding to use (never
null)
-
getEncodableMimeTypes
-
getEncodableMimeTypes
-
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<T extends tools.jackson.databind.ObjectMapper>
-
getEncodeHints
public Map<String,Object> getEncodeHints(@Nullable org.springframework.core.ResolvableType actualType, org.springframework.core.ResolvableType elementType, @Nullable MediaType mediaType, ServerHttpRequest request, ServerHttpResponse response) Description copied from interface:HttpMessageEncoderGet decoding hints based on the server request or annotations on the target controller method parameter.- Specified by:
getEncodeHintsin interfaceHttpMessageEncoder<T extends tools.jackson.databind.ObjectMapper>- Parameters:
actualType- the actual source type to encode, possibly a reactive wrapper and sourced fromMethodParameter, i.e. providing access to method annotations.elementType- the element type withinFlux/Monothat we're trying to encode.request- the current requestresponse- the current response- Returns:
- a Map with hints, possibly empty
-
getAnnotation
protected <A extends Annotation> @Nullable A getAnnotation(org.springframework.core.MethodParameter parameter, Class<A> annotType) - Specified by:
getAnnotationin classJacksonCodecSupport<T extends tools.jackson.databind.ObjectMapper>
-