Skip to content

Commit 0a0ddeb

Browse files
committed
Upgrade to Jackson 3.0.0-rc9
Remove URL-based API calls from the `JacksonJsonObjectMapper` since it is removed in Jackson 3 now. Consequence of: FasterXML/jackson-databind#5263
1 parent af19e5d commit 0a0ddeb

File tree

4 files changed

+39
-47
lines changed

4 files changed

+39
-47
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ ext {
6969
hsqldbVersion = '2.7.4'
7070
h2Version = '2.3.232'
7171
jacksonVersion = '2.20.0'
72-
jackson3Version = '3.0.0-rc8'
72+
jackson3Version = '3.0.0-rc9'
7373
jaxbVersion = '4.0.5'
7474
jcifsVersion = '2.1.40'
7575
jeroMqVersion = '0.6.0'

spring-integration-core/src/main/java/org/springframework/integration/support/json/JacksonJsonObjectMapper.java

Lines changed: 28 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import java.io.Reader;
2323
import java.io.Writer;
2424
import java.lang.reflect.Type;
25-
import java.net.URL;
2625
import java.util.Collection;
2726
import java.util.Map;
2827

@@ -97,68 +96,62 @@ public void toJson(Object value, Writer writer) throws IOException {
9796
@Override
9897
public JsonNode toJsonNode(Object json) throws IOException {
9998
try {
100-
if (json instanceof String) {
101-
return this.jsonMapper.readTree((String) json);
99+
if (json instanceof String stringValue) {
100+
return this.jsonMapper.readTree(stringValue);
102101
}
103-
else if (json instanceof byte[]) {
104-
return this.jsonMapper.readTree((byte[]) json);
102+
else if (json instanceof byte[] bytesValue) {
103+
return this.jsonMapper.readTree(bytesValue);
105104
}
106-
else if (json instanceof File) {
107-
return this.jsonMapper.readTree((File) json);
105+
else if (json instanceof File fileValue) {
106+
return this.jsonMapper.readTree(fileValue);
108107
}
109-
else if (json instanceof URL) {
110-
return this.jsonMapper.readTree((URL) json);
108+
else if (json instanceof InputStream inputStreamValue) {
109+
return this.jsonMapper.readTree(inputStreamValue);
111110
}
112-
else if (json instanceof InputStream) {
113-
return this.jsonMapper.readTree((InputStream) json);
114-
}
115-
else if (json instanceof Reader) {
116-
return this.jsonMapper.readTree((Reader) json);
111+
else if (json instanceof Reader readerValue) {
112+
return this.jsonMapper.readTree(readerValue);
117113
}
118114
}
119-
catch (JacksonException e) {
115+
catch (JacksonException ex) {
120116
if (!(json instanceof String) && !(json instanceof byte[])) {
121-
throw new IOException(e);
117+
throw new IOException(ex);
122118
}
123119
// Otherwise the input might not be valid JSON, fallback to TextNode with JsonMapper.valueToTree()
124120
}
125121

126122
try {
127123
return this.jsonMapper.valueToTree(json);
128124
}
129-
catch (JacksonException e) {
130-
throw new IOException(e);
125+
catch (JacksonException ex) {
126+
throw new IOException(ex);
131127
}
132128
}
133129

134130
@Override
135131
protected <T> T fromJson(Object json, JavaType type) throws IOException {
136132
try {
137-
if (json instanceof String) {
138-
return this.jsonMapper.readValue((String) json, type);
139-
}
140-
else if (json instanceof byte[]) {
141-
return this.jsonMapper.readValue((byte[]) json, type);
133+
if (json instanceof String stringValue) {
134+
return this.jsonMapper.readValue(stringValue, type);
142135
}
143-
else if (json instanceof File) {
144-
return this.jsonMapper.readValue((File) json, type);
136+
else if (json instanceof byte[] bytesValue) {
137+
return this.jsonMapper.readValue(bytesValue, type);
145138
}
146-
else if (json instanceof URL) {
147-
return this.jsonMapper.readValue((URL) json, type);
139+
else if (json instanceof File fileValue) {
140+
return this.jsonMapper.readValue(fileValue, type);
148141
}
149-
else if (json instanceof InputStream) {
150-
return this.jsonMapper.readValue((InputStream) json, type);
142+
else if (json instanceof InputStream inputStreamValue) {
143+
return this.jsonMapper.readValue(inputStreamValue, type);
151144
}
152-
else if (json instanceof Reader) {
153-
return this.jsonMapper.readValue((Reader) json, type);
145+
else if (json instanceof Reader readerValue) {
146+
return this.jsonMapper.readValue(readerValue, type);
154147
}
155148
else {
156149
throw new IllegalArgumentException("'json' argument must be an instance of: " + SUPPORTED_JSON_TYPES
157150
+ " , but gotten: " + json.getClass());
158151
}
159152
}
160-
catch (JacksonException e) {
161-
throw new IOException(e);
153+
catch (JacksonException ex) {
154+
throw new IOException(ex);
162155
}
163156
}
164157

@@ -167,8 +160,8 @@ public <T> T fromJson(JsonParser parser, Type valueType) throws IOException {
167160
try {
168161
return this.jsonMapper.readValue(parser, constructType(valueType));
169162
}
170-
catch (JacksonException e) {
171-
throw new IOException(e);
163+
catch (JacksonException ex) {
164+
throw new IOException(ex);
172165
}
173166
}
174167

spring-integration-core/src/test/java/org/springframework/integration/support/json/JacksonJsonObjectMapperTests.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,20 @@
2323
import java.io.Reader;
2424
import java.io.StringReader;
2525
import java.io.StringWriter;
26-
import java.net.URL;
2726
import java.nio.charset.StandardCharsets;
2827
import java.nio.file.Files;
2928
import java.nio.file.Path;
3029
import java.time.LocalDateTime;
3130
import java.time.ZoneId;
3231
import java.time.ZonedDateTime;
3332
import java.util.Arrays;
34-
import java.util.Collection;
3533
import java.util.Date;
3634
import java.util.List;
3735
import java.util.Map;
3836
import java.util.Optional;
3937
import java.util.Set;
4038
import java.util.stream.Collectors;
39+
import java.util.stream.Stream;
4140

4241
import org.junit.jupiter.api.BeforeEach;
4342
import org.junit.jupiter.api.Test;
@@ -53,6 +52,7 @@
5352

5453
/**
5554
* @author Jooyoung Pyoung
55+
* @author Artem Bilan
5656
*
5757
* @since 7.0
5858
*/
@@ -111,10 +111,6 @@ void testToJsonNodeWithFile() throws IOException {
111111
JsonNode nodeFromFile = mapper.toJsonNode(file);
112112
assertThat(nodeFromFile.get("message").asString()).isEqualTo("hello from file");
113113
assertThat(nodeFromFile.get("number").asInt()).isEqualTo(42);
114-
115-
URL fileUrl = file.toURI().toURL();
116-
JsonNode nodeFromUrl = mapper.toJsonNode(fileUrl);
117-
assertThat(nodeFromUrl).isEqualTo(nodeFromFile);
118114
}
119115
finally {
120116
Files.deleteIfExists(tempFile);
@@ -210,16 +206,18 @@ void testJavaTime() throws IOException {
210206
assertThat(deserialized.zoneDate().toInstant()).isEqualTo(data.zoneDate().toInstant());
211207
}
212208

213-
private Set<String> getModuleNames(Collection<JacksonModule> modules) {
214-
return modules.stream()
209+
private Set<String> getModuleNames(Stream<JacksonModule> modules) {
210+
return modules
215211
.map(JacksonModule::getModuleName)
216212
.collect(Collectors.toUnmodifiableSet());
217213
}
218214

219215
private record TestData(String name, Optional<String> email, Optional<Integer> age) {
216+
220217
}
221218

222219
private record TimeData(LocalDateTime localDate, ZonedDateTime zoneDate) {
220+
223221
}
224222

225223
}

spring-integration-core/src/test/java/org/springframework/integration/support/json/JacksonMessagingUtilsTests.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616

1717
package org.springframework.integration.support.json;
1818

19-
import java.util.Collection;
2019
import java.util.Set;
2120
import java.util.stream.Collectors;
21+
import java.util.stream.Stream;
2222

2323
import org.junit.jupiter.api.BeforeEach;
2424
import org.junit.jupiter.api.Test;
@@ -37,6 +37,7 @@
3737

3838
/**
3939
* @author Jooyoung Pyoung
40+
* @author Artem Bilan
4041
*
4142
* @since 7.0
4243
*/
@@ -125,8 +126,8 @@ void shouldSerializeMimeType() {
125126
assertThat(json).contains("application/json");
126127
}
127128

128-
private static Set<String> getModuleNames(Collection<JacksonModule> modules) {
129-
return modules.stream()
129+
private static Set<String> getModuleNames(Stream<JacksonModule> modules) {
130+
return modules
130131
.map(JacksonModule::getModuleName)
131132
.collect(Collectors.toUnmodifiableSet());
132133
}

0 commit comments

Comments
 (0)