From 7ce980b6b7c4e3cb975865992317568adfc9a73d Mon Sep 17 00:00:00 2001 From: Greg Turnquist Date: Tue, 11 Feb 2020 11:08:50 -0600 Subject: [PATCH] #1193 - Revised usage of Spring Web Encoder APIs. Spring Web has deprecated several Encoder/Decoder APIs and Spring HATEOAS must revise its usage. Original pull request: #1206. --- .../hateoas/config/WebClientConfigurer.java | 34 ++++++------------- 1 file changed, 10 insertions(+), 24 deletions(-) diff --git a/src/main/java/org/springframework/hateoas/config/WebClientConfigurer.java b/src/main/java/org/springframework/hateoas/config/WebClientConfigurer.java index 8e875176..e68c95a6 100644 --- a/src/main/java/org/springframework/hateoas/config/WebClientConfigurer.java +++ b/src/main/java/org/springframework/hateoas/config/WebClientConfigurer.java @@ -75,10 +75,15 @@ public class WebClientConfigurer { CustomCodecs codecs = it.customCodecs(); - encoders.forEach(codecs::encoder); - decoders.stream() // - .peek(applyDefaultConfiguration(codecs)) // - .forEach(codecs::decoder); + encoders.forEach(encoder -> codecs.register(encoder)); + decoders.forEach(decoder -> codecs.registerWithDefaultConfig(decoder, config -> { + + Integer maxInMemorySize = config.maxInMemorySize(); + + if (maxInMemorySize != null) { + decoder.setMaxInMemorySize(maxInMemorySize); + } + })); }; } @@ -103,26 +108,7 @@ public class WebClientConfigurer { public WebClient registerHypermediaTypes(WebClient webClient) { return webClient.mutate() // - .exchangeStrategies(it -> it.codecs(configurer)) // + .codecs(configurer) // .build(); } - - /** - * Returns a {@link Consumer} of {@link AbstractJackson2Decoder} that will copy the default configuration of the given - * {@link CustomCodecs} to a decoder. - * - * @param codecs must not be {@literal null}. - * @return - */ - private static Consumer applyDefaultConfiguration(CustomCodecs codecs) { - - return decoder -> codecs.withDefaultCodecConfig(config -> { - - Integer maxInMemorySize = config.maxInMemorySize(); - - if (maxInMemorySize != null) { - decoder.setMaxInMemorySize(maxInMemorySize); - } - }); - } }