Class JacksonJsonEncoder
java.lang.Object
org.springframework.http.codec.JacksonCodecSupport
org.springframework.http.codec.AbstractJacksonEncoder
org.springframework.http.codec.json.JacksonJsonEncoder
- All Implemented Interfaces:
Encoder<Object>
,HttpMessageEncoder<Object>
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 org.springframework.http.codec.JacksonCodecSupport
FILTER_PROVIDER_HINT, JSON_VIEW_HINT, logger, objectMapperRegistrations
-
Constructor Summary
ConstructorsConstructorDescriptionConstruct a new instance with aJsonMapper
customized with theJacksonModule
s found byMapperBuilder.findModules(ClassLoader)
andProblemDetailJacksonMixin
.JacksonJsonEncoder
(ObjectMapper mapper) Construct a new instance with the providedObjectMapper
.JacksonJsonEncoder
(ObjectMapper mapper, MimeType... mimeTypes) Construct a new instance with the providedObjectMapper
andMimeType
s. -
Method Summary
Modifier and TypeMethodDescriptionprotected ObjectWriter
customizeWriter
(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 org.springframework.http.codec.AbstractJacksonEncoder
canEncode, encode, encodeValue, getAnnotation, getEncodableMimeTypes, getEncodableMimeTypes, getEncodeHints, getJsonEncoding, getStreamingMediaTypes, getStreamingMediaTypeSeparator, setStreamingMediaTypes
Methods inherited from class org.springframework.http.codec.JacksonCodecSupport
getHints, getJavaType, getMimeTypes, getMimeTypes, getObjectMapper, getObjectMapperRegistrations, getObjectMappersForType, getParameter, registerObjectMappersForType, selectObjectMapper, supportsMimeType
-
Constructor Details
-
JacksonJsonEncoder
public JacksonJsonEncoder()Construct a new instance with aJsonMapper
customized with theJacksonModule
s found byMapperBuilder.findModules(ClassLoader)
andProblemDetailJacksonMixin
. -
JacksonJsonEncoder
Construct a new instance with the providedObjectMapper
.- See Also:
-
JacksonJsonEncoder
Construct a new instance with the providedObjectMapper
andMimeType
s.- See Also:
-
-
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
-
customizeWriter
protected ObjectWriter customizeWriter(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
- 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
-