GH-9369: Fix MutableMessageHeaders for serialization

Fixes: #9369

* Implement `MutableMessageHeaders.readResolve()` to reinstate the instance

(cherry picked from commit 02b58277f4)
This commit is contained in:
Mitchell
2024-08-09 05:16:49 +12:00
committed by Spring Builds
parent 7238432c83
commit 2c47b2b6fa
2 changed files with 45 additions and 0 deletions

View File

@@ -16,6 +16,8 @@
package org.springframework.integration.support;
import java.io.ObjectStreamException;
import java.io.Serial;
import java.nio.ByteBuffer;
import java.util.Map;
import java.util.UUID;
@@ -32,6 +34,7 @@ import org.springframework.messaging.MessageHeaders;
* @author David Turanski
* @author Artem Bilan
* @author Nathan Kurtyka
* @author Mitchell McDonald
*
* @since 4.2
*/
@@ -74,6 +77,11 @@ public class MutableMessageHeaders extends MessageHeaders {
return super.getRawHeaders().remove(key);
}
@Serial
private Object readResolve() throws ObjectStreamException {
return new MutableMessageHeaders(this);
}
@Nullable
private static UUID extractId(@Nullable Map<String, Object> headers) {
if (headers != null && headers.containsKey(MessageHeaders.ID)) {