Make JsonObjectDecoder mandatory in JacksonJsonDecoder
This commit is contained in:
parent
92821d9300
commit
1f2fbba89b
|
|
@ -45,22 +45,17 @@ public class JacksonJsonDecoder extends AbstractDecoder<Object> {
|
||||||
|
|
||||||
private final ObjectMapper mapper;
|
private final ObjectMapper mapper;
|
||||||
|
|
||||||
private Decoder<DataBuffer> preProcessor;
|
private final Decoder<DataBuffer> preProcessor = new JsonObjectDecoder();
|
||||||
|
|
||||||
|
|
||||||
public JacksonJsonDecoder() {
|
public JacksonJsonDecoder() {
|
||||||
this(new ObjectMapper(), null);
|
this(new ObjectMapper());
|
||||||
}
|
}
|
||||||
|
|
||||||
public JacksonJsonDecoder(Decoder<DataBuffer> preProcessor) {
|
public JacksonJsonDecoder(ObjectMapper mapper) {
|
||||||
this(new ObjectMapper(), preProcessor);
|
|
||||||
}
|
|
||||||
|
|
||||||
public JacksonJsonDecoder(ObjectMapper mapper, Decoder<DataBuffer> preProcessor) {
|
|
||||||
super(new MimeType("application", "json", StandardCharsets.UTF_8),
|
super(new MimeType("application", "json", StandardCharsets.UTF_8),
|
||||||
new MimeType("application", "*+json", StandardCharsets.UTF_8));
|
new MimeType("application", "*+json", StandardCharsets.UTF_8));
|
||||||
this.mapper = mapper;
|
this.mapper = mapper;
|
||||||
this.preProcessor = preProcessor;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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.ByteBufferEncoder;
|
||||||
import org.springframework.core.codec.support.JacksonJsonDecoder;
|
import org.springframework.core.codec.support.JacksonJsonDecoder;
|
||||||
import org.springframework.core.codec.support.JacksonJsonEncoder;
|
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.StringDecoder;
|
||||||
import org.springframework.core.codec.support.StringEncoder;
|
import org.springframework.core.codec.support.StringEncoder;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
|
|
@ -86,7 +85,7 @@ public final class WebClient {
|
||||||
this.messageEncoders = Arrays.asList(new ByteBufferEncoder(), new StringEncoder(),
|
this.messageEncoders = Arrays.asList(new ByteBufferEncoder(), new StringEncoder(),
|
||||||
new JacksonJsonEncoder());
|
new JacksonJsonEncoder());
|
||||||
this.messageDecoders = Arrays.asList(new ByteBufferDecoder(), new StringDecoder(),
|
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.JacksonJsonEncoder;
|
||||||
import org.springframework.core.codec.support.Jaxb2Decoder;
|
import org.springframework.core.codec.support.Jaxb2Decoder;
|
||||||
import org.springframework.core.codec.support.Jaxb2Encoder;
|
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.StringDecoder;
|
||||||
import org.springframework.core.codec.support.StringEncoder;
|
import org.springframework.core.codec.support.StringEncoder;
|
||||||
import org.springframework.core.convert.converter.Converter;
|
import org.springframework.core.convert.converter.Converter;
|
||||||
|
|
@ -251,7 +250,7 @@ public class WebReactiveConfiguration implements ApplicationContextAware {
|
||||||
}
|
}
|
||||||
if (jackson2Present) {
|
if (jackson2Present) {
|
||||||
JacksonJsonEncoder jacksonEncoder = new JacksonJsonEncoder();
|
JacksonJsonEncoder jacksonEncoder = new JacksonJsonEncoder();
|
||||||
JacksonJsonDecoder jacksonDecoder = new JacksonJsonDecoder(new JsonObjectDecoder());
|
JacksonJsonDecoder jacksonDecoder = new JacksonJsonDecoder();
|
||||||
converters.add(converter(jacksonEncoder, jacksonDecoder));
|
converters.add(converter(jacksonEncoder, jacksonDecoder));
|
||||||
sseDataEncoders.add(jacksonEncoder);
|
sseDataEncoders.add(jacksonEncoder);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -59,8 +59,8 @@ public class JacksonJsonDecoderTests extends AbstractDataBufferAllocatingTestCas
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore // Issues 112 (no generic type), otherwise works
|
@Ignore // Issue 109
|
||||||
public void decodeToListWithoutObjectDecoder() throws Exception {
|
public void decodeToList() throws Exception {
|
||||||
Flux<DataBuffer> source = Flux.just(stringBuffer(
|
Flux<DataBuffer> source = Flux.just(stringBuffer(
|
||||||
"[{\"bar\":\"b1\",\"foo\":\"f1\"},{\"bar\":\"b2\",\"foo\":\"f2\"}]"));
|
"[{\"bar\":\"b1\",\"foo\":\"f1\"},{\"bar\":\"b2\",\"foo\":\"f2\"}]"));
|
||||||
|
|
||||||
|
|
@ -73,8 +73,7 @@ public class JacksonJsonDecoderTests extends AbstractDataBufferAllocatingTestCas
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore // Issue 109
|
public void decodeToFlux() throws Exception {
|
||||||
public void decodeToFluxWithoutObjectDecoder() throws Exception {
|
|
||||||
Flux<DataBuffer> source = Flux.just(stringBuffer(
|
Flux<DataBuffer> source = Flux.just(stringBuffer(
|
||||||
"[{\"bar\":\"b1\",\"foo\":\"f1\"},{\"bar\":\"b2\",\"foo\":\"f2\"}]"));
|
"[{\"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"));
|
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")
|
@SuppressWarnings("unused")
|
||||||
void handle(List<Pojo> list) {
|
void handle(List<Pojo> list) {
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,6 @@ import org.springframework.core.ParameterNameDiscoverer;
|
||||||
import org.springframework.core.annotation.SynthesizingMethodParameter;
|
import org.springframework.core.annotation.SynthesizingMethodParameter;
|
||||||
import org.springframework.core.codec.Decoder;
|
import org.springframework.core.codec.Decoder;
|
||||||
import org.springframework.core.codec.support.JacksonJsonDecoder;
|
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.codec.support.StringDecoder;
|
||||||
import org.springframework.core.convert.support.GenericConversionService;
|
import org.springframework.core.convert.support.GenericConversionService;
|
||||||
import org.springframework.core.convert.support.ReactiveStreamsToCompletableFutureConverter;
|
import org.springframework.core.convert.support.ReactiveStreamsToCompletableFutureConverter;
|
||||||
|
|
@ -93,7 +92,7 @@ public class RequestBodyArgumentResolverTests {
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
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"));
|
this.request = new MockServerHttpRequest(HttpMethod.GET, new URI("/path"));
|
||||||
MockServerHttpResponse response = new MockServerHttpResponse();
|
MockServerHttpResponse response = new MockServerHttpResponse();
|
||||||
DefaultWebSessionManager sessionManager = new DefaultWebSessionManager();
|
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.ByteBufferDecoder;
|
||||||
import org.springframework.core.codec.support.JacksonJsonDecoder;
|
import org.springframework.core.codec.support.JacksonJsonDecoder;
|
||||||
import org.springframework.core.codec.support.JacksonJsonEncoder;
|
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.StringDecoder;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.http.client.reactive.ReactorHttpClientRequestFactory;
|
import org.springframework.http.client.reactive.ReactorHttpClientRequestFactory;
|
||||||
|
|
@ -69,7 +68,7 @@ public class SseIntegrationTests extends AbstractHttpHandlerIntegrationTests {
|
||||||
this.webClient.setMessageDecoders(Arrays.asList(
|
this.webClient.setMessageDecoders(Arrays.asList(
|
||||||
new ByteBufferDecoder(),
|
new ByteBufferDecoder(),
|
||||||
new StringDecoder(false),
|
new StringDecoder(false),
|
||||||
new JacksonJsonDecoder(new JsonObjectDecoder())));
|
new JacksonJsonDecoder()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue