Update Codec API to use Map<String, Object> for hints

Issue: SPR-14557
This commit is contained in:
Sebastien Deleuze
2016-09-12 11:08:01 +02:00
parent b88ed85994
commit b91867cf45
32 changed files with 212 additions and 173 deletions

View File

@@ -38,6 +38,8 @@ import org.springframework.util.MimeType;
*/
public class AbstractJackson2Codec {
public static final String JSON_VIEW_HINT = AbstractJackson2Codec.class.getName() + ".jsonView";
protected static final List<MimeType> JSON_MIME_TYPES = Arrays.asList(
new MimeType("application", "json", StandardCharsets.UTF_8),
new MimeType("application", "*+json", StandardCharsets.UTF_8));

View File

@@ -18,8 +18,8 @@ package org.springframework.http.codec.json;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import com.fasterxml.jackson.annotation.JsonView;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectReader;
@@ -62,7 +62,7 @@ public class Jackson2JsonDecoder extends AbstractJackson2Codec implements Decode
@Override
public boolean canDecode(ResolvableType elementType, MimeType mimeType, Object... hints) {
public boolean canDecode(ResolvableType elementType, MimeType mimeType, Map<String, Object> hints) {
if (mimeType == null) {
return true;
}
@@ -76,7 +76,7 @@ public class Jackson2JsonDecoder extends AbstractJackson2Codec implements Decode
@Override
public Flux<Object> decode(Publisher<DataBuffer> inputStream, ResolvableType elementType,
MimeType mimeType, Object... hints) {
MimeType mimeType, Map<String, Object> hints) {
JsonObjectDecoder objectDecoder = this.fluxObjectDecoder;
return decodeInternal(objectDecoder, inputStream, elementType, mimeType, hints);
@@ -84,14 +84,14 @@ public class Jackson2JsonDecoder extends AbstractJackson2Codec implements Decode
@Override
public Mono<Object> decodeToMono(Publisher<DataBuffer> inputStream, ResolvableType elementType,
MimeType mimeType, Object... hints) {
MimeType mimeType, Map<String, Object> hints) {
JsonObjectDecoder objectDecoder = this.monoObjectDecoder;
return decodeInternal(objectDecoder, inputStream, elementType, mimeType, hints).singleOrEmpty();
}
private Flux<Object> decodeInternal(JsonObjectDecoder objectDecoder, Publisher<DataBuffer> inputStream,
ResolvableType elementType, MimeType mimeType, Object[] hints) {
ResolvableType elementType, MimeType mimeType, Map<String, Object> hints) {
Assert.notNull(inputStream, "'inputStream' must not be null");
Assert.notNull(elementType, "'elementType' must not be null");
@@ -102,14 +102,10 @@ public class Jackson2JsonDecoder extends AbstractJackson2Codec implements Decode
JavaType javaType = getJavaType(elementType.getType(), contextClass);
ObjectReader reader;
JsonView jsonView = (methodParam != null ? methodParam.getParameterAnnotation(JsonView.class) : null);
Class<?> jsonView = (Class<?>)hints.get(AbstractJackson2Codec.JSON_VIEW_HINT);
if (jsonView != null) {
Class<?>[] classes = jsonView.value();
if (classes.length != 1) {
throw new IllegalArgumentException("@JsonView only supported for response body advice " +
"with exactly 1 class argument: " + methodParam);
}
reader = this.mapper.readerWithView(classes[0]).forType(javaType);
reader = this.mapper.readerWithView(jsonView).forType(javaType);
}
else {
reader = this.mapper.readerFor(javaType);

View File

@@ -20,8 +20,8 @@ import java.io.IOException;
import java.io.OutputStream;
import java.nio.ByteBuffer;
import java.util.List;
import java.util.Map;
import com.fasterxml.jackson.annotation.JsonView;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectWriter;
@@ -30,7 +30,6 @@ import org.reactivestreams.Publisher;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import org.springframework.core.MethodParameter;
import org.springframework.core.ResolvableType;
import org.springframework.core.codec.CodecException;
import org.springframework.core.codec.Encoder;
@@ -68,7 +67,7 @@ public class Jackson2JsonEncoder extends AbstractJackson2Codec implements Encode
@Override
public boolean canEncode(ResolvableType elementType, MimeType mimeType, Object... hints) {
public boolean canEncode(ResolvableType elementType, MimeType mimeType, Map<String, Object> hints) {
if (mimeType == null) {
return true;
}
@@ -82,14 +81,14 @@ public class Jackson2JsonEncoder extends AbstractJackson2Codec implements Encode
@Override
public Flux<DataBuffer> encode(Publisher<?> inputStream, DataBufferFactory bufferFactory,
ResolvableType elementType, MimeType mimeType, Object... hints) {
ResolvableType elementType, MimeType mimeType, Map<String, Object> hints) {
Assert.notNull(inputStream, "'inputStream' must not be null");
Assert.notNull(bufferFactory, "'bufferFactory' must not be null");
Assert.notNull(elementType, "'elementType' must not be null");
if (inputStream instanceof Mono) {
return Flux.from(inputStream).map(value -> encodeValue(value, bufferFactory, elementType));
return Flux.from(inputStream).map(value -> encodeValue(value, bufferFactory, elementType, hints));
}
Mono<DataBuffer> startArray = Mono.just(bufferFactory.wrap(START_ARRAY_BUFFER));
@@ -98,31 +97,25 @@ public class Jackson2JsonEncoder extends AbstractJackson2Codec implements Encode
Flux<DataBuffer> array = Flux.from(inputStream)
.concatMap(value -> {
DataBuffer arraySeparator = bufferFactory.wrap(SEPARATOR_BUFFER);
return Flux.just(encodeValue(value, bufferFactory, elementType), arraySeparator);
return Flux.just(encodeValue(value, bufferFactory, elementType, hints), arraySeparator);
});
return Flux.concat(startArray, array.skipLast(1), endArray);
}
private DataBuffer encodeValue(Object value, DataBufferFactory bufferFactory, ResolvableType type) {
private DataBuffer encodeValue(Object value, DataBufferFactory bufferFactory,
ResolvableType type, Map<String, Object> hints) {
TypeFactory typeFactory = this.mapper.getTypeFactory();
JavaType javaType = typeFactory.constructType(type.getType());
MethodParameter returnType =
(type.getSource() instanceof MethodParameter ? (MethodParameter) type.getSource() : null);
if (type.isInstance(value)) {
javaType = getJavaType(type.getType(), null);
}
ObjectWriter writer;
JsonView jsonView = (returnType != null ? returnType.getMethodAnnotation(JsonView.class) : null);
Class<?> jsonView = (Class<?>)hints.get(AbstractJackson2Codec.JSON_VIEW_HINT);
if (jsonView != null) {
Class<?>[] classes = jsonView.value();
if (classes.length != 1) {
throw new IllegalArgumentException("@JsonView only supported for response body advice " +
"with exactly 1 class argument: " + returnType);
}
writer = this.mapper.writerWithView(classes[0]);
writer = this.mapper.writerWithView(jsonView);
}
else {
writer = this.mapper.writer();

View File

@@ -19,6 +19,7 @@ package org.springframework.http.codec.json;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import io.netty.buffer.ByteBuf;
@@ -96,7 +97,7 @@ class JsonObjectDecoder extends AbstractDecoder<DataBuffer> {
@Override
public Flux<DataBuffer> decode(Publisher<DataBuffer> inputStream, ResolvableType elementType,
MimeType mimeType, Object... hints) {
MimeType mimeType, Map<String, Object> hints) {
return Flux.from(inputStream)
.flatMap(new Function<DataBuffer, Publisher<? extends DataBuffer>>() {

View File

@@ -18,6 +18,7 @@ package org.springframework.http.codec.xml;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import javax.xml.XMLConstants;
import javax.xml.bind.JAXBElement;
@@ -75,7 +76,7 @@ public class Jaxb2XmlDecoder extends AbstractDecoder<Object> {
@Override
public boolean canDecode(ResolvableType elementType, MimeType mimeType, Object... hints) {
public boolean canDecode(ResolvableType elementType, MimeType mimeType, Map<String, Object> hints) {
if (super.canDecode(elementType, mimeType, hints)) {
Class<?> outputClass = elementType.getRawClass();
return outputClass.isAnnotationPresent(XmlRootElement.class) ||
@@ -88,11 +89,11 @@ public class Jaxb2XmlDecoder extends AbstractDecoder<Object> {
@Override
public Flux<Object> decode(Publisher<DataBuffer> inputStream, ResolvableType elementType,
MimeType mimeType, Object... hints) {
MimeType mimeType, Map<String, Object> hints) {
Class<?> outputClass = elementType.getRawClass();
Flux<XMLEvent> xmlEventFlux =
this.xmlEventDecoder.decode(inputStream, null, mimeType);
this.xmlEventDecoder.decode(inputStream, null, mimeType, hints);
QName typeName = toQName(outputClass);
Flux<List<XMLEvent>> splitEvents = split(xmlEventFlux, typeName);

View File

@@ -18,6 +18,7 @@ package org.springframework.http.codec.xml;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.util.Map;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.annotation.XmlRootElement;
@@ -52,7 +53,7 @@ public class Jaxb2XmlEncoder extends AbstractSingleValueEncoder<Object> {
@Override
public boolean canEncode(ResolvableType elementType, MimeType mimeType, Object... hints) {
public boolean canEncode(ResolvableType elementType, MimeType mimeType, Map<String, Object> hints) {
if (super.canEncode(elementType, mimeType, hints)) {
Class<?> outputClass = elementType.getRawClass();
return (outputClass.isAnnotationPresent(XmlRootElement.class) ||
@@ -66,7 +67,7 @@ public class Jaxb2XmlEncoder extends AbstractSingleValueEncoder<Object> {
@Override
protected Flux<DataBuffer> encode(Object value, DataBufferFactory dataBufferFactory,
ResolvableType type, MimeType mimeType, Object... hints) {
ResolvableType type, MimeType mimeType, Map<String, Object> hints) {
try {
DataBuffer buffer = dataBufferFactory.allocateBuffer(1024);
OutputStream outputStream = buffer.asOutputStream();

View File

@@ -19,6 +19,7 @@ package org.springframework.http.codec.xml;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import javax.xml.stream.XMLEventReader;
import javax.xml.stream.XMLInputFactory;
@@ -89,7 +90,7 @@ public class XmlEventDecoder extends AbstractDecoder<XMLEvent> {
@Override
@SuppressWarnings("unchecked")
public Flux<XMLEvent> decode(Publisher<DataBuffer> inputStream, ResolvableType elementType,
MimeType mimeType, Object... hints) {
MimeType mimeType, Map<String, Object> hints) {
Flux<DataBuffer> flux = Flux.from(inputStream);
if (useAalto && aaltoPresent) {

View File

@@ -18,7 +18,9 @@ package org.springframework.http.codec.json;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import com.fasterxml.jackson.annotation.JsonView;
import org.junit.Test;
@@ -46,15 +48,16 @@ public class Jackson2JsonDecoderTests extends AbstractDataBufferAllocatingTestCa
public void canDecode() {
Jackson2JsonDecoder decoder = new Jackson2JsonDecoder();
assertTrue(decoder.canDecode(null, MediaType.APPLICATION_JSON));
assertFalse(decoder.canDecode(null, MediaType.APPLICATION_XML));
assertTrue(decoder.canDecode(null, MediaType.APPLICATION_JSON, Collections.emptyMap()));
assertFalse(decoder.canDecode(null, MediaType.APPLICATION_XML, Collections.emptyMap()));
}
@Test
public void decodePojo() {
Flux<DataBuffer> source = Flux.just(stringBuffer("{\"foo\": \"foofoo\", \"bar\": \"barbar\"}"));
ResolvableType elementType = ResolvableType.forClass(Pojo.class);
Flux<Object> flux = new Jackson2JsonDecoder().decode(source, elementType, null);
Flux<Object> flux = new Jackson2JsonDecoder().decode(source, elementType, null,
Collections.emptyMap());
TestSubscriber.subscribe(flux).assertNoError().assertComplete().
assertValues(new Pojo("foofoo", "barbar"));
@@ -67,7 +70,8 @@ public class Jackson2JsonDecoderTests extends AbstractDataBufferAllocatingTestCa
Method method = getClass().getDeclaredMethod("handle", List.class);
ResolvableType elementType = ResolvableType.forMethodParameter(method, 0);
Mono<Object> mono = new Jackson2JsonDecoder().decodeToMono(source, elementType, null);
Mono<Object> mono = new Jackson2JsonDecoder().decodeToMono(source, elementType,
null, Collections.emptyMap());
TestSubscriber.subscribe(mono).assertNoError().assertComplete().
assertValues(Arrays.asList(new Pojo("f1", "b1"), new Pojo("f2", "b2")));
@@ -79,7 +83,8 @@ public class Jackson2JsonDecoderTests extends AbstractDataBufferAllocatingTestCa
"[{\"bar\":\"b1\",\"foo\":\"f1\"},{\"bar\":\"b2\",\"foo\":\"f2\"}]"));
ResolvableType elementType = ResolvableType.forClass(Pojo.class);
Flux<Object> flux = new Jackson2JsonDecoder().decode(source, elementType, null);
Flux<Object> flux = new Jackson2JsonDecoder().decode(source, elementType, null,
Collections.emptyMap());
TestSubscriber.subscribe(flux).assertNoError().assertComplete().
assertValues(new Pojo("f1", "b1"), new Pojo("f2", "b2"));
@@ -89,10 +94,10 @@ public class Jackson2JsonDecoderTests extends AbstractDataBufferAllocatingTestCa
public void jsonView() throws Exception {
Flux<DataBuffer> source = Flux.just(
stringBuffer("{\"withView1\" : \"with\", \"withView2\" : \"with\", \"withoutView\" : \"without\"}"));
ResolvableType elementType = ResolvableType
.forMethodParameter(JacksonController.class.getMethod("foo", JacksonViewBean.class), 0);
ResolvableType elementType = ResolvableType.forClass(JacksonViewBean.class);
Map<String, Object> hints = Collections.singletonMap(Jackson2JsonDecoder.JSON_VIEW_HINT, MyJacksonView1.class);
Flux<JacksonViewBean> flux = new Jackson2JsonDecoder()
.decode(source, elementType, null).cast(JacksonViewBean.class);
.decode(source, elementType, null, hints).cast(JacksonViewBean.class);
TestSubscriber
.subscribe(flux)
@@ -109,7 +114,8 @@ public class Jackson2JsonDecoderTests extends AbstractDataBufferAllocatingTestCa
public void decodeEmptyBodyToMono() throws Exception {
Flux<DataBuffer> source = Flux.empty();
ResolvableType elementType = ResolvableType.forClass(Pojo.class);
Mono<Object> flux = new Jackson2JsonDecoder().decodeToMono(source, elementType, null);
Mono<Object> flux = new Jackson2JsonDecoder().decodeToMono(source, elementType,
null, Collections.emptyMap());
TestSubscriber.subscribe(flux)
.assertNoError()
@@ -163,12 +169,4 @@ public class Jackson2JsonDecoderTests extends AbstractDataBufferAllocatingTestCa
}
}
private static class JacksonController {
public JacksonViewBean foo(@JsonView(MyJacksonView1.class) JacksonViewBean bean) {
return bean;
}
}
}

View File

@@ -16,6 +16,9 @@
package org.springframework.http.codec.json;
import java.util.Collections;
import java.util.Map;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.annotation.JsonTypeName;
import com.fasterxml.jackson.annotation.JsonView;
@@ -42,8 +45,8 @@ public class Jackson2JsonEncoderTests extends AbstractDataBufferAllocatingTestCa
@Test
public void canEncode() {
assertTrue(this.encoder.canEncode(null, MediaType.APPLICATION_JSON));
assertFalse(this.encoder.canEncode(null, MediaType.APPLICATION_XML));
assertTrue(this.encoder.canEncode(null, MediaType.APPLICATION_JSON, Collections.emptyMap()));
assertFalse(this.encoder.canEncode(null, MediaType.APPLICATION_XML, Collections.emptyMap()));
}
@Test
@@ -54,7 +57,7 @@ public class Jackson2JsonEncoderTests extends AbstractDataBufferAllocatingTestCa
new Pojo("foofoofoo", "barbarbar")
);
ResolvableType type = ResolvableType.forClass(Pojo.class);
Flux<DataBuffer> output = this.encoder.encode(source, this.bufferFactory, type, null);
Flux<DataBuffer> output = this.encoder.encode(source, this.bufferFactory, type, null, Collections.emptyMap());
TestSubscriber.subscribe(output)
.assertComplete()
@@ -74,7 +77,7 @@ public class Jackson2JsonEncoderTests extends AbstractDataBufferAllocatingTestCa
public void encodeWithType() {
Flux<ParentClass> source = Flux.just(new Foo(), new Bar());
ResolvableType type = ResolvableType.forClass(ParentClass.class);
Flux<DataBuffer> output = this.encoder.encode(source, this.bufferFactory, type, null);
Flux<DataBuffer> output = this.encoder.encode(source, this.bufferFactory, type, null, Collections.emptyMap());
TestSubscriber.subscribe(output)
.assertComplete()
@@ -93,8 +96,9 @@ public class Jackson2JsonEncoderTests extends AbstractDataBufferAllocatingTestCa
bean.setWithView2("with");
bean.setWithoutView("without");
ResolvableType type = ResolvableType.forMethodReturnType(JacksonController.class.getMethod("foo"));
Flux<DataBuffer> output = this.encoder.encode(Mono.just(bean), this.bufferFactory, type, null);
ResolvableType type = ResolvableType.forClass(JacksonViewBean.class);
Map<String, Object> hints = Collections.singletonMap(Jackson2JsonEncoder.JSON_VIEW_HINT, MyJacksonView1.class);
Flux<DataBuffer> output = this.encoder.encode(Mono.just(bean), this.bufferFactory, type, null, hints);
TestSubscriber.subscribe(output)
.assertComplete()
@@ -157,13 +161,4 @@ public class Jackson2JsonEncoderTests extends AbstractDataBufferAllocatingTestCa
}
}
private static class JacksonController {
@JsonView(MyJacksonView1.class)
public JacksonViewBean foo() {
return null;
}
}
}

View File

@@ -17,6 +17,7 @@
package org.springframework.http.codec.json;
import java.nio.charset.StandardCharsets;
import java.util.Collections;
import org.junit.Test;
import reactor.core.publisher.Flux;
@@ -36,7 +37,7 @@ public class JsonObjectDecoderTests extends AbstractDataBufferAllocatingTestCase
Flux<DataBuffer> source =
Flux.just(stringBuffer("{\"foo\": \"foofoo\", \"bar\": \"barbar\"}"));
Flux<String> output =
decoder.decode(source, null, null).map(JsonObjectDecoderTests::toString);
decoder.decode(source, null, null, Collections.emptyMap()).map(JsonObjectDecoderTests::toString);
TestSubscriber
.subscribe(output)
.assertValues("{\"foo\": \"foofoo\", \"bar\": \"barbar\"}");
@@ -48,7 +49,7 @@ public class JsonObjectDecoderTests extends AbstractDataBufferAllocatingTestCase
Flux<DataBuffer> source = Flux.just(stringBuffer("{\"foo\": \"foofoo\""),
stringBuffer(", \"bar\": \"barbar\"}"));
Flux<String> output =
decoder.decode(source, null, null).map(JsonObjectDecoderTests::toString);
decoder.decode(source, null, null, Collections.emptyMap()).map(JsonObjectDecoderTests::toString);
TestSubscriber
.subscribe(output)
.assertValues("{\"foo\": \"foofoo\", \"bar\": \"barbar\"}");
@@ -60,7 +61,7 @@ public class JsonObjectDecoderTests extends AbstractDataBufferAllocatingTestCase
Flux<DataBuffer> source = Flux.just(stringBuffer(
"[{\"foo\": \"foofoo\", \"bar\": \"barbar\"},{\"foo\": \"foofoofoo\", \"bar\": \"barbarbar\"}]"));
Flux<String> output =
decoder.decode(source, null, null).map(JsonObjectDecoderTests::toString);
decoder.decode(source, null, null, Collections.emptyMap()).map(JsonObjectDecoderTests::toString);
TestSubscriber
.subscribe(output)
.assertValues("{\"foo\": \"foofoo\", \"bar\": \"barbar\"}",
@@ -74,7 +75,7 @@ public class JsonObjectDecoderTests extends AbstractDataBufferAllocatingTestCase
Flux.just(stringBuffer("[{\"foo\": \"foofoo\", \"bar\""), stringBuffer(
": \"barbar\"},{\"foo\": \"foofoofoo\", \"bar\": \"barbarbar\"}]"));
Flux<String> output =
decoder.decode(source, null, null).map(JsonObjectDecoderTests::toString);
decoder.decode(source, null, null, Collections.emptyMap()).map(JsonObjectDecoderTests::toString);
TestSubscriber
.subscribe(output)
.assertValues("{\"foo\": \"foofoo\", \"bar\": \"barbar\"}",

View File

@@ -16,6 +16,7 @@
package org.springframework.http.codec.xml;
import java.util.Collections;
import java.util.List;
import javax.xml.namespace.QName;
import javax.xml.stream.events.XMLEvent;
@@ -71,23 +72,23 @@ public class Jaxb2XmlDecoderTests extends AbstractDataBufferAllocatingTestCase {
@Test
public void canDecode() {
assertTrue(this.decoder.canDecode(ResolvableType.forClass(Pojo.class),
MediaType.APPLICATION_XML));
MediaType.APPLICATION_XML, Collections.emptyMap()));
assertTrue(this.decoder.canDecode(ResolvableType.forClass(Pojo.class),
MediaType.TEXT_XML));
MediaType.TEXT_XML, Collections.emptyMap()));
assertFalse(this.decoder.canDecode(ResolvableType.forClass(Pojo.class),
MediaType.APPLICATION_JSON));
MediaType.APPLICATION_JSON, Collections.emptyMap()));
assertTrue(this.decoder.canDecode(ResolvableType.forClass(TypePojo.class),
MediaType.APPLICATION_XML));
MediaType.APPLICATION_XML, Collections.emptyMap()));
assertFalse(this.decoder.canDecode(ResolvableType.forClass(getClass()),
MediaType.APPLICATION_XML));
MediaType.APPLICATION_XML, Collections.emptyMap()));
}
@Test
public void splitOneBranches() {
Flux<XMLEvent> xmlEvents = this.xmlEventDecoder
.decode(Flux.just(stringBuffer(POJO_ROOT)), null, null);
.decode(Flux.just(stringBuffer(POJO_ROOT)), null, null, Collections.emptyMap());
Flux<List<XMLEvent>> result = this.decoder.split(xmlEvents, new QName("pojo"));
TestSubscriber
@@ -112,7 +113,7 @@ public class Jaxb2XmlDecoderTests extends AbstractDataBufferAllocatingTestCase {
@Test
public void splitMultipleBranches() {
Flux<XMLEvent> xmlEvents = this.xmlEventDecoder
.decode(Flux.just(stringBuffer(POJO_CHILD)), null, null);
.decode(Flux.just(stringBuffer(POJO_CHILD)), null, null, Collections.emptyMap());
Flux<List<XMLEvent>> result = this.decoder.split(xmlEvents, new QName("pojo"));
TestSubscriber
@@ -160,8 +161,8 @@ public class Jaxb2XmlDecoderTests extends AbstractDataBufferAllocatingTestCase {
@Test
public void decodeSingleXmlRootElement() throws Exception {
Flux<DataBuffer> source = Flux.just(stringBuffer(POJO_ROOT));
Flux<Object> output =
this.decoder.decode(source, ResolvableType.forClass(Pojo.class), null);
Flux<Object> output = this.decoder.decode(source, ResolvableType.forClass(Pojo.class),
null, Collections.emptyMap());
TestSubscriber
.subscribe(output)
@@ -173,8 +174,8 @@ public class Jaxb2XmlDecoderTests extends AbstractDataBufferAllocatingTestCase {
@Test
public void decodeSingleXmlTypeElement() throws Exception {
Flux<DataBuffer> source = Flux.just(stringBuffer(POJO_ROOT));
Flux<Object> output = this.decoder
.decode(source, ResolvableType.forClass(TypePojo.class), null);
Flux<Object> output = this.decoder.decode(source, ResolvableType.forClass(TypePojo.class),
null, Collections.emptyMap());
TestSubscriber
.subscribe(output)
@@ -186,8 +187,8 @@ public class Jaxb2XmlDecoderTests extends AbstractDataBufferAllocatingTestCase {
@Test
public void decodeMultipleXmlRootElement() throws Exception {
Flux<DataBuffer> source = Flux.just(stringBuffer(POJO_CHILD));
Flux<Object> output =
this.decoder.decode(source, ResolvableType.forClass(Pojo.class), null);
Flux<Object> output = this.decoder.decode(source, ResolvableType.forClass(Pojo.class),
null, Collections.emptyMap());
TestSubscriber
.subscribe(output)
@@ -199,8 +200,8 @@ public class Jaxb2XmlDecoderTests extends AbstractDataBufferAllocatingTestCase {
@Test
public void decodeMultipleXmlTypeElement() throws Exception {
Flux<DataBuffer> source = Flux.just(stringBuffer(POJO_CHILD));
Flux<Object> output = this.decoder
.decode(source, ResolvableType.forClass(TypePojo.class), null);
Flux<Object> output = this.decoder.decode(source, ResolvableType.forClass(TypePojo.class),
null, Collections.emptyMap());
TestSubscriber
.subscribe(output)

View File

@@ -17,6 +17,7 @@
package org.springframework.http.codec.xml;
import java.nio.charset.StandardCharsets;
import java.util.Collections;
import org.junit.Test;
import reactor.core.publisher.Flux;
@@ -45,18 +46,18 @@ public class Jaxb2XmlEncoderTests extends AbstractDataBufferAllocatingTestCase {
@Test
public void canEncode() {
assertTrue(this.encoder.canEncode(ResolvableType.forClass(Pojo.class),
MediaType.APPLICATION_XML));
MediaType.APPLICATION_XML, Collections.emptyMap()));
assertTrue(this.encoder.canEncode(ResolvableType.forClass(Pojo.class),
MediaType.TEXT_XML));
MediaType.TEXT_XML, Collections.emptyMap()));
assertFalse(this.encoder.canEncode(ResolvableType.forClass(Pojo.class),
MediaType.APPLICATION_JSON));
MediaType.APPLICATION_JSON, Collections.emptyMap()));
assertTrue(this.encoder.canEncode(
ResolvableType.forClass(Jaxb2XmlDecoderTests.TypePojo.class),
MediaType.APPLICATION_XML));
MediaType.APPLICATION_XML, Collections.emptyMap()));
assertFalse(this.encoder.canEncode(ResolvableType.forClass(getClass()),
MediaType.APPLICATION_XML));
MediaType.APPLICATION_XML, Collections.emptyMap()));
}
@Test
@@ -64,7 +65,7 @@ public class Jaxb2XmlEncoderTests extends AbstractDataBufferAllocatingTestCase {
Flux<Pojo> source = Flux.just(new Pojo("foofoo", "barbar"), new Pojo("foofoofoo", "barbarbar"));
Flux<DataBuffer> output = this.encoder.encode(source, this.bufferFactory,
ResolvableType.forClass(Pojo.class),
MediaType.APPLICATION_XML);
MediaType.APPLICATION_XML, Collections.emptyMap());
TestSubscriber
.subscribe(output)
.assertValuesWith(dataBuffer -> {

View File

@@ -16,6 +16,7 @@
package org.springframework.http.codec.xml;
import java.util.Collections;
import javax.xml.stream.events.XMLEvent;
import org.junit.Test;
@@ -44,7 +45,7 @@ public class XmlEventDecoderTests extends AbstractDataBufferAllocatingTestCase {
public void toXMLEventsAalto() {
Flux<XMLEvent> events =
this.decoder.decode(Flux.just(stringBuffer(XML)), null, null);
this.decoder.decode(Flux.just(stringBuffer(XML)), null, null, Collections.emptyMap());
TestSubscriber
.subscribe(events)
@@ -66,7 +67,7 @@ public class XmlEventDecoderTests extends AbstractDataBufferAllocatingTestCase {
decoder.useAalto = false;
Flux<XMLEvent> events =
this.decoder.decode(Flux.just(stringBuffer(XML)), null, null);
this.decoder.decode(Flux.just(stringBuffer(XML)), null, null, Collections.emptyMap());
TestSubscriber
.subscribe(events)