Class JacksonJsonEncoder
java.lang.Object
org.springframework.http.codec.JacksonCodecSupport<tools.jackson.databind.json.JsonMapper>
org.springframework.http.codec.AbstractJacksonEncoder<tools.jackson.databind.json.JsonMapper>
org.springframework.http.codec.json.JacksonJsonEncoder
- All Implemented Interfaces:
Encoder<Object>, HttpMessageEncoder<Object>
public class JacksonJsonEncoder
extends AbstractJacksonEncoder<tools.jackson.databind.json.JsonMapper>
Encode from an
Object
stream to a byte stream of JSON objects using
Jackson 3.x. For non-streaming
use cases, Flux
elements are collected into a List
before
serialization for performance reason.
The default constructor loads JacksonModule
s
found by MapperBuilder.findModules(ClassLoader)
.
- Since:
- 7.0
- Author:
- Sebastien Deleuze
- See Also:
-
Field Summary
Fields inherited from class JacksonCodecSupport
FILTER_PROVIDER_HINT, JSON_VIEW_HINT, logger, mapperRegistrations
-
Constructor Summary
ConstructorsConstructorDescriptionConstruct a new instance with aJsonMapper
customized with theJacksonModule
s found byMapperBuilder.findModules(ClassLoader)
andProblemDetailJacksonMixin
.JacksonJsonEncoder
(tools.jackson.databind.json.JsonMapper mapper) Construct a new instance with the providedJsonMapper
.JacksonJsonEncoder
(tools.jackson.databind.json.JsonMapper mapper, MimeType... mimeTypes) Construct a new instance with the providedJsonMapper
andMimeType
s. -
Method Summary
Modifier and TypeMethodDescriptionprotected tools.jackson.databind.ObjectWriter
customizeWriter
(tools.jackson.databind.ObjectWriter writer, @Nullable MimeType mimeType, ResolvableType elementType, @Nullable Map<String, Object> hints) Subclasses can use this method to customize theObjectWriter
used for writing values.Return the supported media type(s) forProblemDetail
.Methods inherited from class AbstractJacksonEncoder
canEncode, encode, encodeValue, getAnnotation, getEncodableMimeTypes, getEncodableMimeTypes, getEncodeHints, getJsonEncoding, getStreamingMediaTypes, getStreamingMediaTypeSeparator, setStreamingMediaTypes
Methods inherited from class JacksonCodecSupport
getHints, getJavaType, getMapper, getMapperRegistrations, getMappersForType, getMimeTypes, getMimeTypes, getParameter, registerMappersForType, selectMapper, supportsMimeType
-
Constructor Details
-
JacksonJsonEncoder
public JacksonJsonEncoder()Construct a new instance with aJsonMapper
customized with theJacksonModule
s found byMapperBuilder.findModules(ClassLoader)
andProblemDetailJacksonMixin
. -
JacksonJsonEncoder
public JacksonJsonEncoder(tools.jackson.databind.json.JsonMapper mapper) Construct a new instance with the providedJsonMapper
.- See Also:
-
JacksonJsonEncoder
-
-
Method Details
-
getMediaTypesForProblemDetail
Description copied from class:JacksonCodecSupport
Return the supported media type(s) forProblemDetail
. By default, an empty list, unless overridden in subclasses.- Overrides:
getMediaTypesForProblemDetail
in classJacksonCodecSupport<tools.jackson.databind.json.JsonMapper>
-
customizeWriter
protected tools.jackson.databind.ObjectWriter customizeWriter(tools.jackson.databind.ObjectWriter writer, @Nullable MimeType mimeType, ResolvableType elementType, @Nullable Map<String, Object> hints) Description copied from class:AbstractJacksonEncoder
Subclasses can use this method to customize theObjectWriter
used for writing values.- Overrides:
customizeWriter
in classAbstractJacksonEncoder<tools.jackson.databind.json.JsonMapper>
- 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
ObjectWriter
to use
-