Package org.springframework.http.codec.json

# Class Jackson2JsonEncoder

java.lang.Object
org.springframework.http.codec.json.Jackson2CodecSupport
org.springframework.http.codec.json.AbstractJackson2Encoder
org.springframework.http.codec.json.Jackson2JsonEncoder

All Implemented Interfaces:
  `org.springframework.core.codec.Encoder<Object>`, `HttpMessageEncoder<Object>`

public class Jackson2JsonEncoder extends AbstractJackson2Encoder
Encode from an `Object` stream to a byte stream of JSON objects using Jackson 2.x. For non-streaming use cases, `Flux` elements are collected into a `List` before serialization for performance reason.

Since:
  5.0
Author:
  Sebastien Deleuze, Arjen Poutsma
See Also:
  - `Jackson2JsonDecoder`

## Field Summary

### Fields inherited from class org.springframework.http.codec.json.Jackson2CodecSupport

`JSON_VIEW_HINT, logger`

## Constructor Summary

Constructors
Constructor
Description
`Jackson2JsonEncoder()`
`Jackson2JsonEncoder(ObjectMapper mapper, org.springframework.util.MimeType... mimeTypes)`

## Method Summary

Modifier and Type
Method
Description
`protected ObjectWriter`
`customizeWriter(ObjectWriter writer, org.springframework.util.MimeType mimeType, org.springframework.core.ResolvableType elementType, Map<String,Object> hints)`
Subclasses can use this method to customize the `ObjectWriter` used for writing values.
`protected List<org.springframework.util.MimeType>`
`getMediaTypesForProblemDetail()`
Return the supported media type(s) for `ProblemDetail`.

### Methods inherited from class org.springframework.http.codec.json.AbstractJackson2Encoder

`canEncode, encode, encodeValue, getAnnotation, getEncodableMimeTypes, getEncodableMimeTypes, getEncodeHints, getJsonEncoding, getStreamingMediaTypes, getStreamingMediaTypeSeparator, setStreamingMediaTypes`

### Methods inherited from class org.springframework.http.codec.json.Jackson2CodecSupport

`getHints, getJavaType, getMimeTypes, getMimeTypes, getObjectMapper, getObjectMapperRegistrations, getObjectMappersForType, getParameter, logWarningIfNecessary, registerObjectMappersForType, selectObjectMapper, setObjectMapper, supportsMimeType`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### Jackson2JsonEncoder

public Jackson2JsonEncoder()

### Jackson2JsonEncoder

public Jackson2JsonEncoder(ObjectMapper mapper, org.springframework.util.MimeType... mimeTypes)

## Method Details

### getMediaTypesForProblemDetail

protected List<org.springframework.util.MimeType> getMediaTypesForProblemDetail()
Description copied from class: `Jackson2CodecSupport`
Return the supported media type(s) for `ProblemDetail`. By default, an empty list, unless overridden in subclasses.

Overrides:
  `getMediaTypesForProblemDetail` in class `Jackson2CodecSupport`

### customizeWriter

protected ObjectWriter customizeWriter(ObjectWriter writer, @Nullable org.springframework.util.MimeType mimeType, org.springframework.core.ResolvableType elementType, @Nullable Map<String,Object> hints)
Description copied from class: `AbstractJackson2Encoder`
Subclasses can use this method to customize the `ObjectWriter` used for writing values.

Overrides:
  `customizeWriter` in class `AbstractJackson2Encoder`
Parameters:
  `writer` - the writer instance to customize
  `mimeType` - the selected MIME type
  `elementType` - the type of element values to write
  `hints` - a map with serialization hints; the Reactor Context, when available, may be accessed under the key `ContextView.class.getName()`
Returns:
  the customized `ObjectWriter` to use