Skip to content

Commit b84dfad

Browse files
committed
GH-10058: Add Jackson 3 (de)serializer support
Related to: #10058 * Add Jackson3-compatible messaging (de)serializers * Add Jackson 3 `messagingAwareMapper()` support * Maintain existing Jackson 2 functionality Signed-off-by: Jooyoung Pyoung <[email protected]>
1 parent c1efa8c commit b84dfad

22 files changed

+1098
-284
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright 2017-present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.integration.support.json;
18+
19+
import java.io.IOException;
20+
21+
import com.fasterxml.jackson.databind.DeserializationContext;
22+
import com.fasterxml.jackson.databind.JsonNode;
23+
24+
import org.springframework.integration.message.AdviceMessage;
25+
import org.springframework.integration.support.MutableMessageHeaders;
26+
import org.springframework.messaging.Message;
27+
import org.springframework.messaging.MessageHeaders;
28+
29+
/**
30+
* The {@link MessageJackson2Deserializer} implementation for the {@link AdviceMessage}.
31+
*
32+
* @author Artem Bilan
33+
* @author Ngoc Nhan
34+
*
35+
* @since 4.3.10
36+
*/
37+
public class AdviceMessageJackson2Deserializer extends MessageJackson2Deserializer<AdviceMessage<?>> {
38+
39+
private static final long serialVersionUID = 1L;
40+
41+
@SuppressWarnings("unchecked")
42+
public AdviceMessageJackson2Deserializer() {
43+
super((Class<AdviceMessage<?>>) (Class<?>) AdviceMessage.class);
44+
}
45+
46+
@Override
47+
protected AdviceMessage<?> buildMessage(MutableMessageHeaders headers, Object payload, JsonNode root,
48+
DeserializationContext ctxt) throws IOException {
49+
Message<?> inputMessage = getMapper().readValue(root.get("inputMessage").traverse(), Message.class);
50+
return new AdviceMessage<>(payload, (MessageHeaders) headers, inputMessage);
51+
}
52+
53+
}

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

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,20 @@
1616

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

19-
import java.io.IOException;
20-
21-
import com.fasterxml.jackson.databind.DeserializationContext;
22-
import com.fasterxml.jackson.databind.JsonNode;
19+
import tools.jackson.core.JacksonException;
20+
import tools.jackson.databind.DeserializationContext;
21+
import tools.jackson.databind.JsonNode;
2322

2423
import org.springframework.integration.message.AdviceMessage;
2524
import org.springframework.integration.support.MutableMessageHeaders;
2625
import org.springframework.messaging.Message;
27-
import org.springframework.messaging.MessageHeaders;
2826

2927
/**
3028
* The {@link MessageJacksonDeserializer} implementation for the {@link AdviceMessage}.
3129
*
32-
* @author Artem Bilan
33-
* @author Ngoc Nhan
30+
* @author Jooyoung Pyoung
3431
*
35-
* @since 4.3.10
32+
* @since 7.0
3633
*/
3734
public class AdviceMessageJacksonDeserializer extends MessageJacksonDeserializer<AdviceMessage<?>> {
3835

@@ -45,9 +42,9 @@ public AdviceMessageJacksonDeserializer() {
4542

4643
@Override
4744
protected AdviceMessage<?> buildMessage(MutableMessageHeaders headers, Object payload, JsonNode root,
48-
DeserializationContext ctxt) throws IOException {
49-
Message<?> inputMessage = getMapper().readValue(root.get("inputMessage").traverse(), Message.class);
50-
return new AdviceMessage<>(payload, (MessageHeaders) headers, inputMessage);
45+
DeserializationContext ctxt) throws JacksonException {
46+
Message<?> inputMessage = getMapper().readValue(root.get("inputMessage").traverse(ctxt), Message.class);
47+
return new AdviceMessage<>(payload, headers, inputMessage);
5148
}
5249

5350
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,13 @@
7070
* </pre>
7171
* <p>
7272
* To add more packages, create an object mapper using
73-
* {@link JacksonJsonUtils#messagingAwareMapper(String...)}.
73+
* {@link Jackson2MessagingAwareMapperUtils#messagingAwareMapper(String...)}.
7474
* <p>
7575
* A constructor is provided allowing the provision of such a configured object mapper.
7676
*
7777
* @author Gary Russell
7878
* @author Artem Bilan
79+
* @author Jooyoung Pyoung
7980
*
8081
* @since 5.0
8182
*
@@ -109,7 +110,7 @@ public EmbeddedJsonHeadersMessageMapper() {
109110
* @see PatternMatchUtils#smartMatch(String, String...)
110111
*/
111112
public EmbeddedJsonHeadersMessageMapper(String... headerPatterns) {
112-
this(JacksonJsonUtils.messagingAwareMapper(), headerPatterns);
113+
this(Jackson2MessagingAwareMapperUtils.messagingAwareMapper(), headerPatterns);
113114
}
114115

115116
/**
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright 2017-present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.integration.support.json;
18+
19+
import java.io.IOException;
20+
21+
import com.fasterxml.jackson.databind.DeserializationContext;
22+
import com.fasterxml.jackson.databind.JsonNode;
23+
import com.fasterxml.jackson.databind.type.TypeFactory;
24+
25+
import org.springframework.integration.support.MutableMessageHeaders;
26+
import org.springframework.messaging.Message;
27+
import org.springframework.messaging.support.ErrorMessage;
28+
29+
/**
30+
* The {@link MessageJackson2Deserializer} implementation for the {@link ErrorMessage}.
31+
*
32+
* @author Artem Bilan
33+
*
34+
* @since 4.3.10
35+
*/
36+
public class ErrorMessageJackson2Deserializer extends MessageJackson2Deserializer<ErrorMessage> {
37+
38+
private static final long serialVersionUID = 1L;
39+
40+
@SuppressWarnings("this-escape")
41+
public ErrorMessageJackson2Deserializer() {
42+
super(ErrorMessage.class);
43+
setPayloadType(TypeFactory.defaultInstance().constructType(Throwable.class));
44+
}
45+
46+
@Override
47+
protected ErrorMessage buildMessage(MutableMessageHeaders headers, Object payload, JsonNode root,
48+
DeserializationContext ctxt) throws IOException {
49+
Message<?> originalMessage = getMapper().readValue(root.get("originalMessage").traverse(), Message.class);
50+
return new ErrorMessage((Throwable) payload, headers, originalMessage);
51+
}
52+
53+
}

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

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

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

19-
import java.io.IOException;
20-
21-
import com.fasterxml.jackson.databind.DeserializationContext;
22-
import com.fasterxml.jackson.databind.JsonNode;
23-
import com.fasterxml.jackson.databind.type.TypeFactory;
19+
import tools.jackson.core.JacksonException;
20+
import tools.jackson.databind.DeserializationContext;
21+
import tools.jackson.databind.JsonNode;
22+
import tools.jackson.databind.type.TypeFactory;
2423

2524
import org.springframework.integration.support.MutableMessageHeaders;
2625
import org.springframework.messaging.Message;
@@ -29,9 +28,9 @@
2928
/**
3029
* The {@link MessageJacksonDeserializer} implementation for the {@link ErrorMessage}.
3130
*
32-
* @author Artem Bilan
31+
* @author Jooyoung Pyoung
3332
*
34-
* @since 4.3.10
33+
* @since 7.0
3534
*/
3635
public class ErrorMessageJacksonDeserializer extends MessageJacksonDeserializer<ErrorMessage> {
3736

@@ -40,13 +39,13 @@ public class ErrorMessageJacksonDeserializer extends MessageJacksonDeserializer<
4039
@SuppressWarnings("this-escape")
4140
public ErrorMessageJacksonDeserializer() {
4241
super(ErrorMessage.class);
43-
setPayloadType(TypeFactory.defaultInstance().constructType(Throwable.class));
42+
setPayloadType(TypeFactory.createDefaultInstance().constructType(Throwable.class));
4443
}
4544

4645
@Override
4746
protected ErrorMessage buildMessage(MutableMessageHeaders headers, Object payload, JsonNode root,
48-
DeserializationContext ctxt) throws IOException {
49-
Message<?> originalMessage = getMapper().readValue(root.get("originalMessage").traverse(), Message.class);
47+
DeserializationContext ctxt) throws JacksonException {
48+
Message<?> originalMessage = getMapper().readValue(root.get("originalMessage").traverse(ctxt), Message.class);
5049
return new ErrorMessage((Throwable) payload, headers, originalMessage);
5150
}
5251

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright 2017-present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.integration.support.json;
18+
19+
import java.io.IOException;
20+
21+
import com.fasterxml.jackson.databind.DeserializationContext;
22+
import com.fasterxml.jackson.databind.JsonNode;
23+
24+
import org.springframework.integration.support.MutableMessageHeaders;
25+
import org.springframework.messaging.support.GenericMessage;
26+
27+
/**
28+
* The {@link MessageJackson2Deserializer} implementation for the {@link GenericMessage}.
29+
*
30+
* @author Artem Bilan
31+
*
32+
* @since 4.3.10
33+
*/
34+
public class GenericMessageJackson2Deserializer extends MessageJackson2Deserializer<GenericMessage<?>> {
35+
36+
private static final long serialVersionUID = 1L;
37+
38+
@SuppressWarnings("unchecked")
39+
public GenericMessageJackson2Deserializer() {
40+
super((Class<GenericMessage<?>>) (Class<?>) GenericMessage.class);
41+
}
42+
43+
@Override
44+
protected GenericMessage<?> buildMessage(MutableMessageHeaders headers, Object payload, JsonNode root,
45+
DeserializationContext ctxt) throws IOException {
46+
return new GenericMessage<Object>(payload, headers);
47+
}
48+
49+
}

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,19 @@
1616

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

19-
import java.io.IOException;
20-
21-
import com.fasterxml.jackson.databind.DeserializationContext;
22-
import com.fasterxml.jackson.databind.JsonNode;
19+
import tools.jackson.core.JacksonException;
20+
import tools.jackson.databind.DeserializationContext;
21+
import tools.jackson.databind.JsonNode;
2322

2423
import org.springframework.integration.support.MutableMessageHeaders;
2524
import org.springframework.messaging.support.GenericMessage;
2625

2726
/**
2827
* The {@link MessageJacksonDeserializer} implementation for the {@link GenericMessage}.
2928
*
30-
* @author Artem Bilan
29+
* @author Jooyoung Pyoung
3130
*
32-
* @since 4.3.10
31+
* @since 7.0
3332
*/
3433
public class GenericMessageJacksonDeserializer extends MessageJacksonDeserializer<GenericMessage<?>> {
3534

@@ -42,7 +41,7 @@ public GenericMessageJacksonDeserializer() {
4241

4342
@Override
4443
protected GenericMessage<?> buildMessage(MutableMessageHeaders headers, Object payload, JsonNode root,
45-
DeserializationContext ctxt) throws IOException {
44+
DeserializationContext ctxt) throws JacksonException {
4645
return new GenericMessage<Object>(payload, headers);
4746
}
4847

0 commit comments

Comments
 (0)