提交 1f2fbba8 编写于 作者: S Sebastien Deleuze

Make JsonObjectDecoder mandatory in JacksonJsonDecoder

上级 92821d93
......@@ -45,22 +45,17 @@ public class JacksonJsonDecoder extends AbstractDecoder<Object> {
private final ObjectMapper mapper;
private Decoder<DataBuffer> preProcessor;
private final Decoder<DataBuffer> preProcessor = new JsonObjectDecoder();
public JacksonJsonDecoder() {
this(new ObjectMapper(), null);
this(new ObjectMapper());
}
public JacksonJsonDecoder(Decoder<DataBuffer> preProcessor) {
this(new ObjectMapper(), preProcessor);
}
public JacksonJsonDecoder(ObjectMapper mapper, Decoder<DataBuffer> 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
......
......@@ -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());
}
/**
......
......@@ -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 {
......
......@@ -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<DataBuffer> 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<DataBuffer> 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<DataBuffer> 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<Object> 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<DataBuffer> source = Flux.just(stringBuffer(
"[{\"bar\":\"b1\",\"foo\":\"f1\"},{\"bar\":\"b2\",\"foo\":\"f2\"}]"));
ResolvableType elementType = ResolvableType.forClass(Pojo.class);
Flux<Object> 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<Pojo> list) {
}
......
......@@ -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();
......
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册