Top Description Inners Methods
org.springframework.http.codec

public Interface CodecConfigurer

Known Direct Subinterfaces
org.springframework.http.codec.ServerCodecConfigurer, org.springframework.http.codec.ClientCodecConfigurer
Known Direct Implementers
org.springframework.http.codec.support.BaseCodecConfigurer
Imports
java.util.List, java.util.function.Consumer, org.springframework.core.codec.Decoder, .Encoder, org.springframework.lang.Nullable

Defines a common interface for configuring either client or server HTTP message readers and writers. This is used as follows:

HTTP message readers and writers are divided into 3 categories that are ordered as follows:

  1. Typed readers and writers that support specific types, e.g. byte[], String.
  2. Object readers and writers, e.g. JSON, XML.
  3. Catch-all readers or writers, e.g. String with any media type.

Typed and object readers are further subdivided and ordered as follows:

  1. Default HTTP reader and writer registrations.
  2. Custom readers and writers.
Author
Rossen Stoyanchev
Since
5.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface
CodecConfigurer.CustomCodecs

Registry for custom HTTP message readers and writers.

public static interface
CodecConfigurer.DefaultCodecConfig

Exposes the values of properties configured through defaultCodecs() that are applied to default codecs.

public static interface
CodecConfigurer.DefaultCodecs

Customize or replace the HTTP message readers and writers registered by default.

public static interface
CodecConfigurer.MultipartCodecs

Registry and container for multipart HTTP message writers.

Method Summary

Modifier and TypeMethod and Description
public CodecConfigurer
clone()

Create a copy of this CodecConfigurer.

public CodecConfigurer.CustomCodecs
customCodecs()

Register custom HTTP message readers or writers in addition to the ones registered by default.

public CodecConfigurer.DefaultCodecs
defaultCodecs()

Provides a way to customize or replace HTTP message readers and writers registered by default.

public List<HttpMessageReader<?>>
getReaders()

Obtain the configured HTTP message readers.

public List<HttpMessageWriter<?>>
getWriters()

Obtain the configured HTTP message writers.

public void
registerDefaults(boolean registerDefaults)

Provides a way to completely turn off registration of default HTTP message readers and writers, and instead rely only on the ones provided via customCodecs().

Method Detail

cloneback to summary
public CodecConfigurer clone()

Create a copy of this CodecConfigurer. The returned clone has its own lists of default and custom codecs and generally can be configured independently. Keep in mind however that codec instances (if any are configured) are themselves not cloned.

Since
5.1.12
customCodecsback to summary
public CodecConfigurer.CustomCodecs customCodecs()

Register custom HTTP message readers or writers in addition to the ones registered by default.

defaultCodecsback to summary
public CodecConfigurer.DefaultCodecs defaultCodecs()

Provides a way to customize or replace HTTP message readers and writers registered by default.

See Also
registerDefaults(boolean)
getReadersback to summary
public List<HttpMessageReader<?>> getReaders()

Obtain the configured HTTP message readers.

getWritersback to summary
public List<HttpMessageWriter<?>> getWriters()

Obtain the configured HTTP message writers.

registerDefaultsback to summary
public void registerDefaults(boolean registerDefaults)

Provides a way to completely turn off registration of default HTTP message readers and writers, and instead rely only on the ones provided via customCodecs().

By default this is set to "true" in which case default registrations are made; setting this to false disables default registrations.

org.springframework.http.codec back to summary

public Interface CodecConfigurer.CustomCodecs

Known Direct Implementers
org.springframework.http.codec.support.BaseCodecConfigurer.DefaultCustomCodecs

Registry for custom HTTP message readers and writers.

Method Summary

Modifier and TypeMethod and Description
public void
decoder(Decoder<?>
the decoder to add
decoder
)

Deprecated as of 5.1.13, use register(Object) or registerWithDefaultConfig(Object) instead.
Add a custom Decoder internally wrapped with DecoderHttpMessageReader).
public void
encoder(Encoder<?>
the encoder to add
encoder
)

Deprecated as of 5.1.13, use register(Object) or registerWithDefaultConfig(Object) instead.
Add a custom Encoder, internally wrapped with EncoderHttpMessageWriter.
public void
reader(HttpMessageReader<?>
the reader to add
reader
)

Deprecated as of 5.1.13, use register(Object) or registerWithDefaultConfig(Object) instead.
Add a custom HttpMessageReader.
public void
register(Object
the codec to register
codec
)

Register a custom codec.

public void
registerWithDefaultConfig(Object
the codec to register and apply default config to
codec
)

Variant of register(Object) that also applies the below properties, if configured, via defaultCodecs():

public void
registerWithDefaultConfig(Object
the codec to register
codec
,
Consumer<CodecConfigurer.DefaultCodecConfig>
consumer of the default config
configConsumer
)

Variant of register(Object) that also allows the caller to apply the properties from DefaultCodecConfig to the given codec.

public void
withDefaultCodecConfig(Consumer<CodecConfigurer.DefaultCodecConfig>
the default codecs configuration callback
codecsConfigConsumer
)

Register a callback for the configuration applied to default codecs.
public void
writer(HttpMessageWriter<?>
the writer to add
writer
)

Deprecated as of 5.1.13, use register(Object) or registerWithDefaultConfig(Object) instead.
Add a custom HttpMessageWriter.

Method Detail

decoderback to summary
public void decoder(Decoder<?> decoder)

Deprecated

as of 5.1.13, use register(Object) or registerWithDefaultConfig(Object) instead.

Add a custom Decoder internally wrapped with DecoderHttpMessageReader).

Parameters
decoder:Decoder<?>

the decoder to add

Annotations
@Deprecated
encoderback to summary
public void encoder(Encoder<?> encoder)

Deprecated

as of 5.1.13, use register(Object) or registerWithDefaultConfig(Object) instead.

Add a custom Encoder, internally wrapped with EncoderHttpMessageWriter.

Parameters
encoder:Encoder<?>

the encoder to add

Annotations
@Deprecated
readerback to summary
public void reader(HttpMessageReader<?> reader)

Deprecated

as of 5.1.13, use register(Object) or registerWithDefaultConfig(Object) instead.

Add a custom HttpMessageReader. For readers of type DecoderHttpMessageReader consider using the shortcut decoder(Decoder) instead.

Parameters
reader:HttpMessageReader<?>

the reader to add

Annotations
@Deprecated
registerback to summary
public void register(Object codec)

Register a custom codec. This is expected to be one of the following:

Parameters
codec:Object

the codec to register

Since
5.1.13
registerWithDefaultConfigback to summary
public void registerWithDefaultConfig(Object codec)

Variant of register(Object) that also applies the below properties, if configured, via defaultCodecs():

The properties are applied every time getReaders() or getWriters() are used to obtain the list of configured readers or writers.

Parameters
codec:Object

the codec to register and apply default config to

Since
5.1.13
registerWithDefaultConfigback to summary
public void registerWithDefaultConfig(Object codec, Consumer<CodecConfigurer.DefaultCodecConfig> configConsumer)

Variant of register(Object) that also allows the caller to apply the properties from DefaultCodecConfig to the given codec. If you want to apply all the properties, prefer using registerWithDefaultConfig(Object).

The consumer is called every time getReaders() or getWriters() are used to obtain the list of configured readers or writers.

Parameters
codec:Object

the codec to register

configConsumer:Consumer<CodecConfigurer.DefaultCodecConfig>

consumer of the default config

Since
5.1.13
withDefaultCodecConfigback to summary
public void withDefaultCodecConfig(Consumer<CodecConfigurer.DefaultCodecConfig> codecsConfigConsumer)

Register a callback for the configuration applied to default codecs. This allows custom codecs to follow general guidelines applied to default ones, such as logging details and limiting the amount of buffered data.

Parameters
codecsConfigConsumer:Consumer<CodecConfigurer.DefaultCodecConfig>

the default codecs configuration callback

Annotations
@Deprecated
writerback to summary
public void writer(HttpMessageWriter<?> writer)

Deprecated

as of 5.1.13, use register(Object) or registerWithDefaultConfig(Object) instead.

Add a custom HttpMessageWriter. For writers of type EncoderHttpMessageWriter consider using the shortcut encoder(Encoder) instead.

Parameters
writer:HttpMessageWriter<?>

the writer to add

Annotations
@Deprecated
org.springframework.http.codec back to summary

public Interface CodecConfigurer.DefaultCodecConfig

Known Direct Implementers
org.springframework.http.codec.support.BaseDefaultCodecs

Exposes the values of properties configured through defaultCodecs() that are applied to default codecs. The main purpose of this interface is to provide access to them so they can also be applied to custom codecs if needed.
Since
5.1.12
See Also
CustomCodecs#registerWithDefaultConfig(Object, Consumer)

Method Summary

Modifier and TypeMethod and Description
public Boolean
isEnableLoggingRequestDetails()

Whether to log form data at DEBUG level, and headers at TRACE level.

public Integer
maxInMemorySize()

Get the configured limit on the number of bytes that can be buffered whenever the input stream needs to be aggregated.

Method Detail

isEnableLoggingRequestDetailsback to summary
public Boolean isEnableLoggingRequestDetails()

Whether to log form data at DEBUG level, and headers at TRACE level. Both may contain sensitive information.

Annotations
@Nullable
maxInMemorySizeback to summary
public Integer maxInMemorySize()

Get the configured limit on the number of bytes that can be buffered whenever the input stream needs to be aggregated.

Annotations
@Nullable
org.springframework.http.codec back to summary

public Interface CodecConfigurer.DefaultCodecs

Known Direct Subinterfaces
org.springframework.http.codec.ServerCodecConfigurer.ServerDefaultCodecs, org.springframework.http.codec.ClientCodecConfigurer.ClientDefaultCodecs
Known Direct Implementers
org.springframework.http.codec.support.BaseDefaultCodecs

Customize or replace the HTTP message readers and writers registered by default. The options are further extended by ClientDefaultCodecs and ServerDefaultCodecs.

Method Summary

Modifier and TypeMethod and Description
public void
configureDefaultCodec(Consumer<Object>
the consumer to apply
codecConsumer
)

Register a consumer to apply to default config instances.

public void
enableLoggingRequestDetails(boolean
whether to enable or not
enable
)

Whether to log form data at DEBUG level, and headers at TRACE level.

public void
jackson2JsonDecoder(Decoder<?>
the decoder instance to use
decoder
)

Override the default Jackson JSON Decoder.

public void
jackson2JsonEncoder(Encoder<?>
the encoder instance to use
encoder
)

Override the default Jackson JSON Encoder.

public void
jackson2SmileDecoder(Decoder<?>
the decoder instance to use
decoder
)

Override the default Jackson Smile Decoder.

public void
jackson2SmileEncoder(Encoder<?>
the encoder instance to use
encoder
)

Override the default Jackson Smile Encoder.

public void
jaxb2Decoder(Decoder<?>
the decoder instance to use
decoder
)

Override the default JAXB2 Decoder.

public void
jaxb2Encoder(Encoder<?>
the encoder instance to use
encoder
)

Override the default JABX2 Encoder.

public void
kotlinSerializationCborDecoder(Decoder<?>
the decoder instance to use
decoder
)

Override the default Kotlin Serialization CBOR Decoder.

public void
kotlinSerializationCborEncoder(Encoder<?>
the encoder instance to use
encoder
)

Override the default Kotlin Serialization CBOR Encoder.

public void
kotlinSerializationJsonDecoder(Decoder<?>
the decoder instance to use
decoder
)

Override the default Kotlin Serialization JSON Decoder.

public void
kotlinSerializationJsonEncoder(Encoder<?>
the encoder instance to use
encoder
)

Override the default Kotlin Serialization JSON Encoder.

public void
kotlinSerializationProtobufDecoder(Decoder<?>
the decoder instance to use
decoder
)

Override the default Kotlin Serialization Protobuf Decoder.

public void
kotlinSerializationProtobufEncoder(Encoder<?>
the encoder instance to use
encoder
)

Override the default Kotlin Serialization Protobuf Encoder.

public void
maxInMemorySize(int
the max number of bytes to buffer, or -1 for unlimited
byteCount
)

Configure a limit on the number of bytes that can be buffered whenever the input stream needs to be aggregated.

public CodecConfigurer.MultipartCodecs
multipartCodecs()

Configure encoders or writers for use with MultipartHttpMessageWriter.

public void
multipartReader(HttpMessageReader<?>
the message reader to use for multipart requests.
reader
)

Configure the HttpMessageReader to use for multipart requests.

public void
protobufDecoder(Decoder<?>
the decoder instance to use
decoder
)

Override the default Protobuf Decoder.

public void
protobufEncoder(Encoder<?>
the encoder instance to use
encoder
)

Override the default Protobuf Encoder.

Method Detail

configureDefaultCodecback to summary
public void configureDefaultCodec(Consumer<Object> codecConsumer)

Register a consumer to apply to default config instances. This can be used to configure rather than replace a specific codec or multiple codecs. The consumer is applied to every default Encoder, Decoder, HttpMessageReader and HttpMessageWriter instance.

Parameters
codecConsumer:Consumer<Object>

the consumer to apply

Since
5.3.4
enableLoggingRequestDetailsback to summary
public void enableLoggingRequestDetails(boolean enable)

Whether to log form data at DEBUG level, and headers at TRACE level. Both may contain sensitive information.

By default set to false so that request details are not shown.

Parameters
enable:boolean

whether to enable or not

Since
5.1
jackson2JsonDecoderback to summary
public void jackson2JsonDecoder(Decoder<?> decoder)

Override the default Jackson JSON Decoder.

Note that maxInMemorySize(int), if configured, will be applied to the given decoder.

Parameters
decoder:Decoder<?>

the decoder instance to use

See Also
org.springframework.http.codec.json.Jackson2JsonDecoder
jackson2JsonEncoderback to summary
public void jackson2JsonEncoder(Encoder<?> encoder)

Override the default Jackson JSON Encoder.

Parameters
encoder:Encoder<?>

the encoder instance to use

See Also
org.springframework.http.codec.json.Jackson2JsonEncoder
jackson2SmileDecoderback to summary
public void jackson2SmileDecoder(Decoder<?> decoder)

Override the default Jackson Smile Decoder.

Note that maxInMemorySize(int), if configured, will be applied to the given decoder.

Parameters
decoder:Decoder<?>

the decoder instance to use

See Also
org.springframework.http.codec.json.Jackson2SmileDecoder
jackson2SmileEncoderback to summary
public void jackson2SmileEncoder(Encoder<?> encoder)

Override the default Jackson Smile Encoder.

Parameters
encoder:Encoder<?>

the encoder instance to use

See Also
org.springframework.http.codec.json.Jackson2SmileEncoder
jaxb2Decoderback to summary
public void jaxb2Decoder(Decoder<?> decoder)

Override the default JAXB2 Decoder.

Note that maxInMemorySize(int), if configured, will be applied to the given decoder.

Parameters
decoder:Decoder<?>

the decoder instance to use

Since
5.1.3
See Also
org.springframework.http.codec.xml.Jaxb2XmlDecoder
jaxb2Encoderback to summary
public void jaxb2Encoder(Encoder<?> encoder)

Override the default JABX2 Encoder.

Parameters
encoder:Encoder<?>

the encoder instance to use

Since
5.1.3
See Also
org.springframework.http.codec.xml.Jaxb2XmlEncoder
kotlinSerializationCborDecoderback to summary
public void kotlinSerializationCborDecoder(Decoder<?> decoder)

Override the default Kotlin Serialization CBOR Decoder.

Parameters
decoder:Decoder<?>

the decoder instance to use

Since
6.0
See Also
org.springframework.http.codec.cbor.KotlinSerializationCborDecoder
kotlinSerializationCborEncoderback to summary
public void kotlinSerializationCborEncoder(Encoder<?> encoder)

Override the default Kotlin Serialization CBOR Encoder.

Parameters
encoder:Encoder<?>

the encoder instance to use

Since
6.0
See Also
org.springframework.http.codec.cbor.KotlinSerializationCborDecoder
kotlinSerializationJsonDecoderback to summary
public void kotlinSerializationJsonDecoder(Decoder<?> decoder)

Override the default Kotlin Serialization JSON Decoder.

Parameters
decoder:Decoder<?>

the decoder instance to use

Since
5.3
See Also
org.springframework.http.codec.json.KotlinSerializationJsonDecoder
kotlinSerializationJsonEncoderback to summary
public void kotlinSerializationJsonEncoder(Encoder<?> encoder)

Override the default Kotlin Serialization JSON Encoder.

Parameters
encoder:Encoder<?>

the encoder instance to use

Since
5.3
See Also
org.springframework.http.codec.json.KotlinSerializationJsonEncoder
kotlinSerializationProtobufDecoderback to summary
public void kotlinSerializationProtobufDecoder(Decoder<?> decoder)

Override the default Kotlin Serialization Protobuf Decoder.

Parameters
decoder:Decoder<?>

the decoder instance to use

Since
6.0
See Also
org.springframework.http.codec.protobuf.KotlinSerializationProtobufDecoder
kotlinSerializationProtobufEncoderback to summary
public void kotlinSerializationProtobufEncoder(Encoder<?> encoder)

Override the default Kotlin Serialization Protobuf Encoder.

Parameters
encoder:Encoder<?>

the encoder instance to use

Since
6.0
See Also
org.springframework.http.codec.protobuf.KotlinSerializationProtobufEncoder
maxInMemorySizeback to summary
public void maxInMemorySize(int byteCount)

Configure a limit on the number of bytes that can be buffered whenever the input stream needs to be aggregated. This can be a result of decoding to a single DataBuffer, ByteBuffer, byte[], Resource, String, etc. It can also occur when splitting the input stream, e.g. delimited text, in which case the limit applies to data buffered between delimiters.

By default this is not set, in which case individual codec defaults apply. All codecs are limited to 256K by default.

Parameters
byteCount:int

the max number of bytes to buffer, or -1 for unlimited

Since
5.1.11
multipartCodecsback to summary
public CodecConfigurer.MultipartCodecs multipartCodecs()

Configure encoders or writers for use with MultipartHttpMessageWriter.

Since
6.0.3
multipartReaderback to summary
public void multipartReader(HttpMessageReader<?> reader)

Configure the HttpMessageReader to use for multipart requests.

Note that maxInMemorySize(int) and/or enableLoggingRequestDetails(boolean), if configured, will be applied to the given reader, if applicable.

Parameters
reader:HttpMessageReader<?>

the message reader to use for multipart requests.

Since
6.0.3
protobufDecoderback to summary
public void protobufDecoder(Decoder<?> decoder)

Override the default Protobuf Decoder.

Note that maxInMemorySize(int), if configured, will be applied to the given decoder.

Parameters
decoder:Decoder<?>

the decoder instance to use

Since
5.1
See Also
org.springframework.http.codec.protobuf.ProtobufDecoder
protobufEncoderback to summary
public void protobufEncoder(Encoder<?> encoder)

Override the default Protobuf Encoder.

Parameters
encoder:Encoder<?>

the encoder instance to use

Since
5.1
See Also
org.springframework.http.codec.protobuf.ProtobufEncoder, org.springframework.http.codec.protobuf.ProtobufHttpMessageWriter
org.springframework.http.codec back to summary

public Interface CodecConfigurer.MultipartCodecs

Known Direct Implementers
org.springframework.http.codec.support.BaseDefaultCodecs.DefaultMultipartCodecs

Registry and container for multipart HTTP message writers.
Since
6.0.3

Method Summary

Modifier and TypeMethod and Description
public CodecConfigurer.MultipartCodecs
encoder(Encoder<?>
the encoder to add
encoder
)

Add a Part Encoder, internally wrapped with EncoderHttpMessageWriter.

public CodecConfigurer.MultipartCodecs
writer(HttpMessageWriter<?>
the writer to add
writer
)

Add a Part HttpMessageWriter.

Method Detail

encoderback to summary
public CodecConfigurer.MultipartCodecs encoder(Encoder<?> encoder)

Add a Part Encoder, internally wrapped with EncoderHttpMessageWriter.

Parameters
encoder:Encoder<?>

the encoder to add

writerback to summary
public CodecConfigurer.MultipartCodecs writer(HttpMessageWriter<?> writer)

Add a Part HttpMessageWriter. For writers of type EncoderHttpMessageWriter consider using the shortcut encoder(Encoder) instead.

Parameters
writer:HttpMessageWriter<?>

the writer to add