Skip to content

Commit 51e6320

Browse files
authored
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 * Revert class naming to maintain compatibility * Keep existing `*JacksonDeserializer` classes unchanged * Add new `*Jackson3Deserializer` classes for Jackson 3 support * Remove `Jackson3` suffix from deserializer/serializer classes * Copy `DEFAULT_TRUSTED_PACKAGES` from `JacksonJsonUtils` for future deprecation * Inline dedicated method and constants in test * Configure checkstyle `NoWhitespaceBefore` tokens to allow varargs spacing * Add `@Nullable` for JSpecify nullability * Fix ClassLoader reference in `JacksonMessagingUtils` * Add missing `@Nullable` for varargs param Signed-off-by: Jooyoung Pyoung <[email protected]>
1 parent 1bd1c13 commit 51e6320

File tree

10 files changed

+789
-1
lines changed

10 files changed

+789
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright 2025-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 tools.jackson.core.JacksonException;
20+
import tools.jackson.databind.DeserializationContext;
21+
import tools.jackson.databind.JsonNode;
22+
23+
import org.springframework.integration.message.AdviceMessage;
24+
import org.springframework.integration.support.MutableMessageHeaders;
25+
import org.springframework.messaging.Message;
26+
27+
/**
28+
* The {@link MessageJsonDeserializer} implementation for the {@link AdviceMessage}.
29+
*
30+
* @author Jooyoung Pyoung
31+
*
32+
* @since 7.0
33+
*/
34+
public class AdviceMessageJsonDeserializer extends MessageJsonDeserializer<AdviceMessage<?>> {
35+
36+
@SuppressWarnings("unchecked")
37+
public AdviceMessageJsonDeserializer() {
38+
super((Class<AdviceMessage<?>>) (Class<?>) AdviceMessage.class);
39+
}
40+
41+
@Override
42+
protected AdviceMessage<?> buildMessage(MutableMessageHeaders headers, Object payload, JsonNode root,
43+
DeserializationContext ctxt) throws JacksonException {
44+
45+
Message<?> inputMessage = getMapper().readValue(root.get("inputMessage").traverse(ctxt), Message.class);
46+
return new AdviceMessage<>(payload, headers, inputMessage);
47+
}
48+
49+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright 2025-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 tools.jackson.core.JacksonException;
20+
import tools.jackson.databind.DeserializationContext;
21+
import tools.jackson.databind.JsonNode;
22+
import tools.jackson.databind.type.TypeFactory;
23+
24+
import org.springframework.integration.support.MutableMessageHeaders;
25+
import org.springframework.messaging.Message;
26+
import org.springframework.messaging.support.ErrorMessage;
27+
28+
/**
29+
* The {@link MessageJsonDeserializer} implementation for the {@link ErrorMessage}.
30+
*
31+
* @author Jooyoung Pyoung
32+
*
33+
* @since 7.0
34+
*/
35+
public class ErrorMessageJsonDeserializer extends MessageJsonDeserializer<ErrorMessage> {
36+
37+
@SuppressWarnings("this-escape")
38+
public ErrorMessageJsonDeserializer() {
39+
super(ErrorMessage.class);
40+
setPayloadType(TypeFactory.createDefaultInstance().constructType(Throwable.class));
41+
}
42+
43+
@Override
44+
protected ErrorMessage buildMessage(MutableMessageHeaders headers, Object payload, JsonNode root,
45+
DeserializationContext ctxt) throws JacksonException {
46+
47+
Message<?> originalMessage = getMapper().readValue(root.get("originalMessage").traverse(ctxt), Message.class);
48+
return new ErrorMessage((Throwable) payload, headers, originalMessage);
49+
}
50+
51+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright 2025-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 tools.jackson.core.JacksonException;
20+
import tools.jackson.databind.DeserializationContext;
21+
import tools.jackson.databind.JsonNode;
22+
23+
import org.springframework.integration.support.MutableMessageHeaders;
24+
import org.springframework.messaging.support.GenericMessage;
25+
26+
/**
27+
* The {@link MessageJsonDeserializer} implementation for the {@link GenericMessage}.
28+
*
29+
* @author Jooyoung Pyoung
30+
*
31+
* @since 7.0
32+
*/
33+
public class GenericMessageJsonDeserializer extends MessageJsonDeserializer<GenericMessage<?>> {
34+
35+
@SuppressWarnings("unchecked")
36+
public GenericMessageJsonDeserializer() {
37+
super((Class<GenericMessage<?>>) (Class<?>) GenericMessage.class);
38+
}
39+
40+
@Override
41+
protected GenericMessage<?> buildMessage(MutableMessageHeaders headers, Object payload, JsonNode root,
42+
DeserializationContext ctxt) throws JacksonException {
43+
44+
return new GenericMessage<>(payload, headers);
45+
}
46+
47+
}

0 commit comments

Comments
 (0)