Expose ClientCodecConfigurer in WebClient.Builder
Using Consumer<ClientCodecConfigurer> instead of Consumer<ExchangeStrategies> eliminates one level of nesting that is also unnecessary since codecs are the only strategy at present. Closes gh-24124
This commit is contained in:
@@ -979,31 +979,21 @@ The following example shows how to do so for client-side requests:
|
||||
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
|
||||
.Java
|
||||
----
|
||||
Consumer<ClientCodecConfigurer> consumer = configurer -> {
|
||||
CustomDecoder customDecoder = new CustomDecoder();
|
||||
configurer.customCodecs().decoder(customDecoder);
|
||||
configurer.customCodecs().withDefaultCodecConfig(config ->
|
||||
customDecoder.maxInMemorySize(config.maxInMemorySize())
|
||||
);
|
||||
}
|
||||
|
||||
WebClient webClient = WebClient.builder()
|
||||
.exchangeStrategies(strategies -> strategies.codecs(consumer))
|
||||
.codecs(configurer -> {
|
||||
CustomDecoder decoder = new CustomDecoder();
|
||||
configurer.customCodecs().registerWithDefaultConfig(decoder);
|
||||
})
|
||||
.build();
|
||||
----
|
||||
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
|
||||
.Kotlin
|
||||
----
|
||||
val consumer: (ClientCodecConfigurer) -> Unit = { configurer ->
|
||||
val customDecoder = CustomDecoder()
|
||||
configurer.customCodecs().decoder(customDecoder)
|
||||
configurer.customCodecs().withDefaultCodecConfig({ config ->
|
||||
customDecoder.maxInMemorySize(config.maxInMemorySize())
|
||||
})
|
||||
}
|
||||
|
||||
val webClient = WebClient.builder()
|
||||
.exchangeStrategies({ strategies -> strategies.codecs(consumer) })
|
||||
.codecs({ configurer ->
|
||||
val decoder = CustomDecoder()
|
||||
configurer.customCodecs().registerWithDefaultConfig(decoder)
|
||||
})
|
||||
.build()
|
||||
----
|
||||
|
||||
|
||||
Reference in New Issue
Block a user