GH-9561: Make DelayedMessageWrapper JSON-serializable

Fixes: #9561
PR: https://github.com/spring-projects/spring-integration/pull/9561

The `DelayHandler.DelayedMessageWrapper` cannot be deserialized when using `RedisMessageStore` and JSON serialization:
```
org.springframework.data.redis.serializer.SerializationException: Could not read JSON:Cannot construct instance of `org.springframework.integration.handler.DelayHandler$DelayedMessageWrapper` (no Creators, like default constructor, exist): cannot deserialize from Object value (no delegate- or property-based Creator)
 at [Source: UNKNOWN; byte offset: #UNKNOWN]
	at org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer.deserialize(GenericJackson2JsonRedisSerializer.java:311)
```

* More code clean up and refactoring in the test

(cherry picked from commit 73bb813b53)
This commit is contained in:
NaccOll
2024-10-22 08:11:57 +08:00
committed by Spring Builds
parent a64d01d4da
commit e3665bf82c
3 changed files with 39 additions and 59 deletions

View File

@@ -31,6 +31,8 @@ import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import java.util.stream.Stream;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.aopalliance.aop.Advice;
import org.springframework.aop.framework.ProxyFactory;
@@ -97,6 +99,7 @@ import org.springframework.util.ObjectUtils;
* @author Artem Bilan
* @author Gary Russell
* @author Christian Tzolov
* @author Youbin Wu
*
* @since 1.0.3
*/
@@ -688,7 +691,10 @@ public class DelayHandler extends AbstractReplyProducingMessageHandler implement
private final Message<?> original;
DelayedMessageWrapper(Message<?> original, long requestDate) {
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
DelayedMessageWrapper(@JsonProperty("original") Message<?> original,
@JsonProperty("requestDate") long requestDate) {
this.original = original;
this.requestDate = requestDate;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2024 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.
@@ -46,6 +46,7 @@ import org.springframework.messaging.support.GenericMessage;
*
* @author Artem Bilan
* @author Gary Russell
* @author Youbin Wu
*
* @since 3.0
*
@@ -63,7 +64,8 @@ public final class JacksonJsonUtils {
"org.springframework.integration.support",
"org.springframework.integration.message",
"org.springframework.integration.store",
"org.springframework.integration.history"
"org.springframework.integration.history",
"org.springframework.integration.handler"
);
private JacksonJsonUtils() {