diff --git a/spring-web-reactive/src/main/java/org/springframework/core/codec/support/JacksonJsonDecoder.java b/spring-web-reactive/src/main/java/org/springframework/core/codec/support/JacksonJsonDecoder.java index 93815729db6b8fdd46908a97ab127dbd54109439..a72f187ed356ae0c37f5f809fb2a8867dd57064c 100644 --- a/spring-web-reactive/src/main/java/org/springframework/core/codec/support/JacksonJsonDecoder.java +++ b/spring-web-reactive/src/main/java/org/springframework/core/codec/support/JacksonJsonDecoder.java @@ -45,22 +45,17 @@ public class JacksonJsonDecoder extends AbstractDecoder { private final ObjectMapper mapper; - private Decoder preProcessor; + private final Decoder preProcessor = new JsonObjectDecoder(); public JacksonJsonDecoder() { - this(new ObjectMapper(), null); + this(new ObjectMapper()); } - public JacksonJsonDecoder(Decoder preProcessor) { - this(new ObjectMapper(), preProcessor); - } - - public JacksonJsonDecoder(ObjectMapper mapper, Decoder preProcessor) { + public JacksonJsonDecoder(ObjectMapper mapper) { super(new MimeType("application", "json", StandardCharsets.UTF_8), new MimeType("application", "*+json", StandardCharsets.UTF_8)); this.mapper = mapper; - this.preProcessor = preProcessor; } @Override diff --git a/spring-web-reactive/src/main/java/org/springframework/web/client/reactive/WebClient.java b/spring-web-reactive/src/main/java/org/springframework/web/client/reactive/WebClient.java index 50f9205c2fbd36e232148bc655061bb88b377697..f38f7b02f83b1d7ef752088272512e68fe4b76bf 100644 --- a/spring-web-reactive/src/main/java/org/springframework/web/client/reactive/WebClient.java +++ b/spring-web-reactive/src/main/java/org/springframework/web/client/reactive/WebClient.java @@ -28,7 +28,6 @@ import org.springframework.core.codec.support.ByteBufferDecoder; import org.springframework.core.codec.support.ByteBufferEncoder; import org.springframework.core.codec.support.JacksonJsonDecoder; import org.springframework.core.codec.support.JacksonJsonEncoder; -import org.springframework.core.codec.support.JsonObjectDecoder; import org.springframework.core.codec.support.StringDecoder; import org.springframework.core.codec.support.StringEncoder; import org.springframework.http.HttpStatus; @@ -86,7 +85,7 @@ public final class WebClient { this.messageEncoders = Arrays.asList(new ByteBufferEncoder(), new StringEncoder(), new JacksonJsonEncoder()); this.messageDecoders = Arrays.asList(new ByteBufferDecoder(), new StringDecoder(), - new JacksonJsonDecoder(new JsonObjectDecoder())); + new JacksonJsonDecoder()); } /** diff --git a/spring-web-reactive/src/main/java/org/springframework/web/reactive/config/WebReactiveConfiguration.java b/spring-web-reactive/src/main/java/org/springframework/web/reactive/config/WebReactiveConfiguration.java index 777157c02fa94582d700c69a7795083c20ef5d2c..f49056c4eb25e4fa0b7543fc65a832cc0971f196 100644 --- a/spring-web-reactive/src/main/java/org/springframework/web/reactive/config/WebReactiveConfiguration.java +++ b/spring-web-reactive/src/main/java/org/springframework/web/reactive/config/WebReactiveConfiguration.java @@ -36,7 +36,6 @@ import org.springframework.core.codec.support.JacksonJsonDecoder; import org.springframework.core.codec.support.JacksonJsonEncoder; import org.springframework.core.codec.support.Jaxb2Decoder; import org.springframework.core.codec.support.Jaxb2Encoder; -import org.springframework.core.codec.support.JsonObjectDecoder; import org.springframework.core.codec.support.StringDecoder; import org.springframework.core.codec.support.StringEncoder; import org.springframework.core.convert.converter.Converter; @@ -251,7 +250,7 @@ public class WebReactiveConfiguration implements ApplicationContextAware { } if (jackson2Present) { JacksonJsonEncoder jacksonEncoder = new JacksonJsonEncoder(); - JacksonJsonDecoder jacksonDecoder = new JacksonJsonDecoder(new JsonObjectDecoder()); + JacksonJsonDecoder jacksonDecoder = new JacksonJsonDecoder(); converters.add(converter(jacksonEncoder, jacksonDecoder)); sseDataEncoders.add(jacksonEncoder); } else { diff --git a/spring-web-reactive/src/test/java/org/springframework/core/codec/support/JacksonJsonDecoderTests.java b/spring-web-reactive/src/test/java/org/springframework/core/codec/support/JacksonJsonDecoderTests.java index c9c9110589258baa0075e04803c3e7914d51f76c..6554bc32fccacc6c4e0da36f95950c5f7281674c 100644 --- a/spring-web-reactive/src/test/java/org/springframework/core/codec/support/JacksonJsonDecoderTests.java +++ b/spring-web-reactive/src/test/java/org/springframework/core/codec/support/JacksonJsonDecoderTests.java @@ -59,8 +59,8 @@ public class JacksonJsonDecoderTests extends AbstractDataBufferAllocatingTestCas } @Test - @Ignore // Issues 112 (no generic type), otherwise works - public void decodeToListWithoutObjectDecoder() throws Exception { + @Ignore // Issue 109 + public void decodeToList() throws Exception { Flux source = Flux.just(stringBuffer( "[{\"bar\":\"b1\",\"foo\":\"f1\"},{\"bar\":\"b2\",\"foo\":\"f2\"}]")); @@ -73,8 +73,7 @@ public class JacksonJsonDecoderTests extends AbstractDataBufferAllocatingTestCas } @Test - @Ignore // Issue 109 - public void decodeToFluxWithoutObjectDecoder() throws Exception { + public void decodeToFlux() throws Exception { Flux source = Flux.just(stringBuffer( "[{\"bar\":\"b1\",\"foo\":\"f1\"},{\"bar\":\"b2\",\"foo\":\"f2\"}]")); @@ -85,32 +84,6 @@ public class JacksonJsonDecoderTests extends AbstractDataBufferAllocatingTestCas assertValues(new Pojo("f1", "b1"), new Pojo("f2", "b2")); } - @Test - @Ignore // Issue 109 - public void decodeToListWithObjectDecoder() throws Exception { - Flux source = Flux.just(stringBuffer( - "[{\"bar\":\"b1\",\"foo\":\"f1\"},{\"bar\":\"b2\",\"foo\":\"f2\"}]")); - - Method method = getClass().getDeclaredMethod("handle", List.class); - ResolvableType elementType = ResolvableType.forMethodParameter(method, 0); - Flux flux = new JacksonJsonDecoder(new JsonObjectDecoder()).decode(source, elementType, null); - - TestSubscriber.subscribe(flux).assertNoError().assertComplete(). - assertValues(Arrays.asList(new Pojo("f1", "b1"), new Pojo("f2", "b2"))); - } - - @Test - public void decodeToFluxWithObjectDecoder() throws Exception { - Flux source = Flux.just(stringBuffer( - "[{\"bar\":\"b1\",\"foo\":\"f1\"},{\"bar\":\"b2\",\"foo\":\"f2\"}]")); - - ResolvableType elementType = ResolvableType.forClass(Pojo.class); - Flux flux = new JacksonJsonDecoder(new JsonObjectDecoder()).decode(source, elementType, null); - - TestSubscriber.subscribe(flux).assertNoError().assertComplete(). - assertValues(new Pojo("f1", "b1"), new Pojo("f2", "b2")); - } - @SuppressWarnings("unused") void handle(List list) { } diff --git a/spring-web-reactive/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestBodyArgumentResolverTests.java b/spring-web-reactive/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestBodyArgumentResolverTests.java index 50bb84234d55401e293887c661fd73741b2e5ec5..6f46067fabc105d3b474952769cac1e2a2faacca 100644 --- a/spring-web-reactive/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestBodyArgumentResolverTests.java +++ b/spring-web-reactive/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestBodyArgumentResolverTests.java @@ -44,7 +44,6 @@ import org.springframework.core.ParameterNameDiscoverer; import org.springframework.core.annotation.SynthesizingMethodParameter; import org.springframework.core.codec.Decoder; import org.springframework.core.codec.support.JacksonJsonDecoder; -import org.springframework.core.codec.support.JsonObjectDecoder; import org.springframework.core.codec.support.StringDecoder; import org.springframework.core.convert.support.GenericConversionService; import org.springframework.core.convert.support.ReactiveStreamsToCompletableFutureConverter; @@ -93,7 +92,7 @@ public class RequestBodyArgumentResolverTests { @Before public void setUp() throws Exception { - this.resolver = resolver(new JacksonJsonDecoder(new JsonObjectDecoder())); + this.resolver = resolver(new JacksonJsonDecoder()); this.request = new MockServerHttpRequest(HttpMethod.GET, new URI("/path")); MockServerHttpResponse response = new MockServerHttpResponse(); DefaultWebSessionManager sessionManager = new DefaultWebSessionManager(); diff --git a/spring-web-reactive/src/test/java/org/springframework/web/reactive/result/method/annotation/SseIntegrationTests.java b/spring-web-reactive/src/test/java/org/springframework/web/reactive/result/method/annotation/SseIntegrationTests.java index f25d567c7ac40d0e7b98b02340ecf2da2befedde..673728f3f76de6fae26f51bd4275770dcbba2bf9 100644 --- a/spring-web-reactive/src/test/java/org/springframework/web/reactive/result/method/annotation/SseIntegrationTests.java +++ b/spring-web-reactive/src/test/java/org/springframework/web/reactive/result/method/annotation/SseIntegrationTests.java @@ -33,7 +33,6 @@ import org.springframework.core.codec.Encoder; import org.springframework.core.codec.support.ByteBufferDecoder; import org.springframework.core.codec.support.JacksonJsonDecoder; import org.springframework.core.codec.support.JacksonJsonEncoder; -import org.springframework.core.codec.support.JsonObjectDecoder; import org.springframework.core.codec.support.StringDecoder; import org.springframework.http.MediaType; import org.springframework.http.client.reactive.ReactorHttpClientRequestFactory; @@ -69,7 +68,7 @@ public class SseIntegrationTests extends AbstractHttpHandlerIntegrationTests { this.webClient.setMessageDecoders(Arrays.asList( new ByteBufferDecoder(), new StringDecoder(false), - new JacksonJsonDecoder(new JsonObjectDecoder()))); + new JacksonJsonDecoder())); } @Override