Upgrade to Jackson Bom 2.13.0
Closes gh-28298
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2021 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.
|
||||
@@ -24,7 +24,7 @@ import java.util.Map;
|
||||
|
||||
import com.fasterxml.jackson.databind.MapperFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import com.fasterxml.jackson.databind.json.JsonMapper;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.core.io.ByteArrayResource;
|
||||
@@ -50,24 +50,18 @@ class JacksonTesterIntegrationTests {
|
||||
|
||||
private JacksonTester<String> stringJson;
|
||||
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
private static final String JSON = "{\"name\":\"Spring\",\"age\":123}";
|
||||
|
||||
@BeforeEach
|
||||
void setup() {
|
||||
this.objectMapper = new ObjectMapper();
|
||||
JacksonTester.initFields(this, this.objectMapper);
|
||||
}
|
||||
|
||||
@Test
|
||||
void typicalTest() throws Exception {
|
||||
JacksonTester.initFields(this, new ObjectMapper());
|
||||
String example = JSON;
|
||||
assertThat(this.simpleJson.parse(example).getObject().getName()).isEqualTo("Spring");
|
||||
}
|
||||
|
||||
@Test
|
||||
void typicalListTest() throws Exception {
|
||||
JacksonTester.initFields(this, new ObjectMapper());
|
||||
String example = "[" + JSON + "]";
|
||||
assertThat(this.listJson.parse(example)).asList().hasSize(1);
|
||||
assertThat(this.listJson.parse(example).getObject().get(0).getName()).isEqualTo("Spring");
|
||||
@@ -75,6 +69,7 @@ class JacksonTesterIntegrationTests {
|
||||
|
||||
@Test
|
||||
void typicalMapTest() throws Exception {
|
||||
JacksonTester.initFields(this, new ObjectMapper());
|
||||
Map<String, Integer> map = new LinkedHashMap<>();
|
||||
map.put("a", 1);
|
||||
map.put("b", 2);
|
||||
@@ -83,6 +78,7 @@ class JacksonTesterIntegrationTests {
|
||||
|
||||
@Test
|
||||
void stringLiteral() throws Exception {
|
||||
JacksonTester.initFields(this, new ObjectMapper());
|
||||
String stringWithSpecialCharacters = "myString";
|
||||
assertThat(this.stringJson.write(stringWithSpecialCharacters)).extractingJsonPathStringValue("@")
|
||||
.isEqualTo(stringWithSpecialCharacters);
|
||||
@@ -90,6 +86,7 @@ class JacksonTesterIntegrationTests {
|
||||
|
||||
@Test
|
||||
void parseSpecialCharactersTest() throws Exception {
|
||||
JacksonTester.initFields(this, new ObjectMapper());
|
||||
// Confirms that the handling of special characters is symmetrical between
|
||||
// the serialization (via the JacksonTester) and the parsing (via json-path). By
|
||||
// default json-path uses SimpleJson as its parser, which has a slightly different
|
||||
@@ -103,7 +100,7 @@ class JacksonTesterIntegrationTests {
|
||||
|
||||
@Test
|
||||
void writeWithView() throws Exception {
|
||||
this.objectMapper.disable(MapperFeature.DEFAULT_VIEW_INCLUSION);
|
||||
JacksonTester.initFields(this, JsonMapper.builder().disable(MapperFeature.DEFAULT_VIEW_INCLUSION).build());
|
||||
ExampleObjectWithView object = new ExampleObjectWithView();
|
||||
object.setName("Spring");
|
||||
object.setAge(123);
|
||||
@@ -115,7 +112,7 @@ class JacksonTesterIntegrationTests {
|
||||
|
||||
@Test
|
||||
void readWithResourceAndView() throws Exception {
|
||||
this.objectMapper.disable(MapperFeature.DEFAULT_VIEW_INCLUSION);
|
||||
JacksonTester.initFields(this, JsonMapper.builder().disable(MapperFeature.DEFAULT_VIEW_INCLUSION).build());
|
||||
ByteArrayResource resource = new ByteArrayResource(JSON.getBytes());
|
||||
ObjectContent<ExampleObjectWithView> content = this.jsonWithView.forView(ExampleObjectWithView.TestView.class)
|
||||
.read(resource);
|
||||
@@ -125,7 +122,7 @@ class JacksonTesterIntegrationTests {
|
||||
|
||||
@Test
|
||||
void readWithReaderAndView() throws Exception {
|
||||
this.objectMapper.disable(MapperFeature.DEFAULT_VIEW_INCLUSION);
|
||||
JacksonTester.initFields(this, JsonMapper.builder().disable(MapperFeature.DEFAULT_VIEW_INCLUSION).build());
|
||||
Reader reader = new StringReader(JSON);
|
||||
ObjectContent<ExampleObjectWithView> content = this.jsonWithView.forView(ExampleObjectWithView.TestView.class)
|
||||
.read(reader);
|
||||
|
||||
Reference in New Issue
Block a user