Skip to content

Commit 4325fc0

Browse files
committed
DelayedMessageWrapper cannot be deserialized when using RedisMessageStore and JSON serialization
1 parent 1de81b6 commit 4325fc0

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

Diff for: spring-integration-core/src/main/java/org/springframework/integration/handler/DelayHandler.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
import java.util.concurrent.locks.ReentrantLock;
3232
import java.util.stream.Stream;
3333

34+
import com.fasterxml.jackson.annotation.JsonCreator;
35+
import com.fasterxml.jackson.annotation.JsonProperty;
3436
import org.aopalliance.aop.Advice;
3537

3638
import org.springframework.aop.framework.ProxyFactory;
@@ -97,6 +99,7 @@
9799
* @author Artem Bilan
98100
* @author Gary Russell
99101
* @author Christian Tzolov
102+
* @author Youbin Wu
100103
*
101104
* @since 1.0.3
102105
*/
@@ -689,7 +692,8 @@ public static final class DelayedMessageWrapper implements Serializable {
689692
@SuppressWarnings("serial")
690693
private final Message<?> original;
691694

692-
DelayedMessageWrapper(Message<?> original, long requestDate) {
695+
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
696+
DelayedMessageWrapper(@JsonProperty("original") Message<?> original, @JsonProperty("requestDate") long requestDate) {
693697
this.original = original;
694698
this.requestDate = requestDate;
695699
}

Diff for: spring-integration-core/src/main/java/org/springframework/integration/support/json/JacksonJsonUtils.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -46,6 +46,7 @@
4646
*
4747
* @author Artem Bilan
4848
* @author Gary Russell
49+
* @author Youbin Wu
4950
*
5051
* @since 3.0
5152
*
@@ -63,7 +64,8 @@ public final class JacksonJsonUtils {
6364
"org.springframework.integration.support",
6465
"org.springframework.integration.message",
6566
"org.springframework.integration.store",
66-
"org.springframework.integration.history"
67+
"org.springframework.integration.history",
68+
"org.springframework.integration.handler"
6769
);
6870

6971
private JacksonJsonUtils() {

Diff for: spring-integration-redis/src/test/java/org/springframework/integration/redis/store/RedisMessageGroupStoreTests.java

+8-2
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,15 @@
3535
import org.junit.jupiter.api.Disabled;
3636
import org.junit.jupiter.api.Test;
3737

38+
import org.springframework.beans.BeanUtils;
3839
import org.springframework.context.support.ClassPathXmlApplicationContext;
3940
import org.springframework.data.redis.connection.RedisConnectionFactory;
4041
import org.springframework.data.redis.core.StringRedisTemplate;
4142
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
4243
import org.springframework.integration.channel.DirectChannel;
4344
import org.springframework.integration.channel.NullChannel;
4445
import org.springframework.integration.channel.QueueChannel;
46+
import org.springframework.integration.handler.DelayHandler;
4547
import org.springframework.integration.history.MessageHistory;
4648
import org.springframework.integration.message.AdviceMessage;
4749
import org.springframework.integration.redis.RedisContainerTest;
@@ -64,6 +66,7 @@
6466
* @author Artem Bilan
6567
* @author Gary Russell
6668
* @author Artem Vozhdayenko
69+
* @author Youbin Wu
6770
*/
6871
class RedisMessageGroupStoreTests implements RedisContainerTest {
6972

@@ -400,11 +403,13 @@ void testJsonSerialization() {
400403
Message<?> mutableMessage = new MutableMessage<>(UUID.randomUUID());
401404
Message<?> adviceMessage = new AdviceMessage<>("foo", genericMessage);
402405
ErrorMessage errorMessage = new ErrorMessage(new RuntimeException("test exception"), mutableMessage);
406+
var delayedMessageWrapperConstructor = BeanUtils.getResolvableConstructor(DelayHandler.DelayedMessageWrapper.class);
407+
Message<?> delayMessage = new GenericMessage<>(BeanUtils.instantiateClass(delayedMessageWrapperConstructor, genericMessage, System.currentTimeMillis()));
403408

404-
store.addMessagesToGroup(this.groupId, genericMessage, mutableMessage, adviceMessage, errorMessage);
409+
store.addMessagesToGroup(this.groupId, genericMessage, mutableMessage, adviceMessage, errorMessage, delayMessage);
405410

406411
MessageGroup messageGroup = store.getMessageGroup(this.groupId);
407-
assertThat(messageGroup.size()).isEqualTo(4);
412+
assertThat(messageGroup.size()).isEqualTo(5);
408413
List<Message<?>> messages = new ArrayList<>(messageGroup.getMessages());
409414
assertThat(messages.get(0)).isEqualTo(genericMessage);
410415
assertThat(messages.get(0).getHeaders()).containsKeys(MessageHistory.HEADER_NAME);
@@ -417,6 +422,7 @@ void testJsonSerialization() {
417422
.isEqualTo(errorMessage.getOriginalMessage());
418423
assertThat(((ErrorMessage) errorMessageResult).getPayload().getMessage())
419424
.isEqualTo(errorMessage.getPayload().getMessage());
425+
assertThat(messages.get(4)).isEqualTo(delayMessage);
420426

421427
Message<Foo> fooMessage = new GenericMessage<>(new Foo("foo"));
422428
try {

0 commit comments

Comments
 (0)