Merge branch '5.1.x'
This commit is contained in:
@@ -42,18 +42,13 @@ import org.springframework.http.MediaType;
|
||||
import org.springframework.http.codec.Pojo;
|
||||
import org.springframework.util.MimeType;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
import static java.util.Collections.emptyMap;
|
||||
import static java.util.Collections.singletonMap;
|
||||
import static java.util.Arrays.*;
|
||||
import static java.util.Collections.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.springframework.core.ResolvableType.forClass;
|
||||
import static org.springframework.http.MediaType.APPLICATION_JSON;
|
||||
import static org.springframework.http.MediaType.APPLICATION_JSON_UTF8;
|
||||
import static org.springframework.http.MediaType.APPLICATION_STREAM_JSON;
|
||||
import static org.springframework.http.MediaType.APPLICATION_XML;
|
||||
import static org.springframework.http.codec.json.Jackson2JsonDecoder.JSON_VIEW_HINT;
|
||||
import static org.springframework.http.codec.json.JacksonViewBean.MyJacksonView1;
|
||||
import static org.springframework.http.codec.json.JacksonViewBean.MyJacksonView3;
|
||||
import static org.springframework.core.ResolvableType.*;
|
||||
import static org.springframework.http.MediaType.*;
|
||||
import static org.springframework.http.codec.json.Jackson2JsonDecoder.*;
|
||||
import static org.springframework.http.codec.json.JacksonViewBean.*;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link Jackson2JsonDecoder}.
|
||||
@@ -67,10 +62,12 @@ public class Jackson2JsonDecoderTests extends AbstractDecoderTestCase<Jackson2Js
|
||||
|
||||
private Pojo pojo2 = new Pojo("f2", "b2");
|
||||
|
||||
|
||||
public Jackson2JsonDecoderTests() {
|
||||
super(new Jackson2JsonDecoder());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@Test
|
||||
public void canDecode() {
|
||||
@@ -83,7 +80,7 @@ public class Jackson2JsonDecoderTests extends AbstractDecoderTestCase<Jackson2Js
|
||||
assertFalse(decoder.canDecode(forClass(Pojo.class), APPLICATION_XML));
|
||||
}
|
||||
|
||||
@Test // SPR-15866
|
||||
@Test // SPR-15866
|
||||
public void canDecodeWithProvidedMimeType() {
|
||||
MimeType textJavascript = new MimeType("text", "javascript", StandardCharsets.UTF_8);
|
||||
Jackson2JsonDecoder decoder = new Jackson2JsonDecoder(new ObjectMapper(), textJavascript);
|
||||
@@ -212,7 +209,6 @@ public class Jackson2JsonDecoderTests extends AbstractDecoderTestCase<Jackson2Js
|
||||
}
|
||||
|
||||
|
||||
|
||||
private static class BeanWithNoDefaultConstructor {
|
||||
|
||||
private final String property1;
|
||||
@@ -231,12 +227,14 @@ public class Jackson2JsonDecoderTests extends AbstractDecoderTestCase<Jackson2Js
|
||||
public String getProperty2() {
|
||||
return this.property2;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@JsonDeserialize(using = Deserializer.class)
|
||||
public static class TestObject {
|
||||
|
||||
private int test;
|
||||
|
||||
public int getTest() {
|
||||
return this.test;
|
||||
}
|
||||
@@ -245,6 +243,7 @@ public class Jackson2JsonDecoderTests extends AbstractDecoderTestCase<Jackson2Js
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class Deserializer extends StdDeserializer<TestObject> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
@@ -254,8 +253,7 @@ public class Jackson2JsonDecoderTests extends AbstractDecoderTestCase<Jackson2Js
|
||||
}
|
||||
|
||||
@Override
|
||||
public TestObject deserialize(JsonParser p,
|
||||
DeserializationContext ctxt) throws IOException {
|
||||
public TestObject deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
|
||||
JsonNode node = p.readValueAsTree();
|
||||
TestObject result = new TestObject();
|
||||
result.setTest(node.get("test").asInt());
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -37,19 +37,20 @@ import org.springframework.core.codec.DecodingException;
|
||||
import org.springframework.core.io.buffer.AbstractLeakCheckingTestCase;
|
||||
import org.springframework.core.io.buffer.DataBuffer;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
import static java.util.Collections.singletonList;
|
||||
import static java.util.Arrays.*;
|
||||
import static java.util.Collections.*;
|
||||
|
||||
/**
|
||||
* @author Arjen Poutsma
|
||||
* @author Rossen Stoyanchev
|
||||
* @author Juergen Hoeller
|
||||
*/
|
||||
public class Jackson2TokenizerTests extends AbstractLeakCheckingTestCase {
|
||||
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
private JsonFactory jsonFactory;
|
||||
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
|
||||
@Before
|
||||
public void createParser() {
|
||||
@@ -57,6 +58,7 @@ public class Jackson2TokenizerTests extends AbstractLeakCheckingTestCase {
|
||||
this.objectMapper = new ObjectMapper(this.jsonFactory);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void doNotTokenizeArrayElements() {
|
||||
testTokenize(
|
||||
@@ -185,7 +187,8 @@ public class Jackson2TokenizerTests extends AbstractLeakCheckingTestCase {
|
||||
Flux<DataBuffer> source = Flux.just(buffer)
|
||||
.concatWith(Flux.error(new RuntimeException()));
|
||||
|
||||
Flux<TokenBuffer> result = Jackson2Tokenizer.tokenize(source, this.jsonFactory, true);
|
||||
Flux<TokenBuffer> result = Jackson2Tokenizer.tokenize(
|
||||
source, this.jsonFactory, this.objectMapper.getDeserializationContext(), true);
|
||||
|
||||
StepVerifier.create(result)
|
||||
.expectError(RuntimeException.class)
|
||||
@@ -195,7 +198,8 @@ public class Jackson2TokenizerTests extends AbstractLeakCheckingTestCase {
|
||||
@Test // SPR-16521
|
||||
public void jsonEOFExceptionIsWrappedAsDecodingError() {
|
||||
Flux<DataBuffer> source = Flux.just(stringBuffer("{\"status\": \"noClosingQuote}"));
|
||||
Flux<TokenBuffer> tokens = Jackson2Tokenizer.tokenize(source, this.jsonFactory, false);
|
||||
Flux<TokenBuffer> tokens = Jackson2Tokenizer.tokenize(
|
||||
source, this.jsonFactory, this.objectMapper.getDeserializationContext(), false);
|
||||
|
||||
StepVerifier.create(tokens)
|
||||
.expectError(DecodingException.class)
|
||||
@@ -204,10 +208,9 @@ public class Jackson2TokenizerTests extends AbstractLeakCheckingTestCase {
|
||||
|
||||
|
||||
private void testTokenize(List<String> source, List<String> expected, boolean tokenizeArrayElements) {
|
||||
|
||||
Flux<TokenBuffer> tokenBufferFlux = Jackson2Tokenizer.tokenize(
|
||||
Flux.fromIterable(source).map(this::stringBuffer),
|
||||
this.jsonFactory,
|
||||
this.jsonFactory, this.objectMapper.getDeserializationContext(),
|
||||
tokenizeArrayElements);
|
||||
|
||||
Flux<String> result = tokenBufferFlux
|
||||
@@ -234,7 +237,6 @@ public class Jackson2TokenizerTests extends AbstractLeakCheckingTestCase {
|
||||
}
|
||||
|
||||
|
||||
|
||||
private static class JSONAssertConsumer implements Consumer<String> {
|
||||
|
||||
private final String expected;
|
||||
@@ -253,4 +255,5 @@ public class Jackson2TokenizerTests extends AbstractLeakCheckingTestCase {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user