From 5f509ac02ed615f5fae5e8ec21c46418e6cdfd06 Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Fri, 2 Feb 2018 12:47:53 -0500 Subject: [PATCH] INT-4394: Fix compatibility with Jackson JSON JIRA: https://jira.spring.io/browse/INT-4394 Looks like Jackson has became much smarter and now it stores the target type for the object, not returned interface. We can't use Jackson annotations on the Framework classes and we can't restrict the `messagingAwareMapper()` `ObjectMapper` just to use fields for all the object passed through it. As a compromise solution we shouldn't use `Collections.unmodifiableList()` in the getter. The copy of the internal collection is pretty enough to protect our object from mutation. **Cherry-pick to 4.3.x (excluding `build.gradle` change)** --- build.gradle | 2 +- .../AggregateMessageDeliveryException.java | 15 +++++++++++---- .../integration/store/MessageGroupMetadata.java | 10 +++++++--- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/build.gradle b/build.gradle index ddff43d1e0..1295e2d071 100644 --- a/build.gradle +++ b/build.gradle @@ -106,7 +106,7 @@ subprojects { subproject -> hibernateVersion = '5.2.10.Final' hsqldbVersion = '2.4.0' h2Version = '1.4.196' - jackson2Version = '2.9.1' + jackson2Version = '2.9.4' javaxActivationVersion = '1.1.1' javaxMailVersion = '1.6.0' jedisVersion = '2.9.0' diff --git a/spring-integration-core/src/main/java/org/springframework/integration/dispatcher/AggregateMessageDeliveryException.java b/spring-integration-core/src/main/java/org/springframework/integration/dispatcher/AggregateMessageDeliveryException.java index 9b2f24a092..8756719431 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/dispatcher/AggregateMessageDeliveryException.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/dispatcher/AggregateMessageDeliveryException.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 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. @@ -16,7 +16,7 @@ package org.springframework.integration.dispatcher; -import java.util.Collections; +import java.util.ArrayList; import java.util.List; import org.springframework.messaging.Message; @@ -28,6 +28,8 @@ import org.springframework.util.StringUtils; * that may try multiple handler invocations within a single dispatch operation. * * @author Mark Fisher + * @author Artem Bilan + * * @since 1.0.3 */ @SuppressWarnings("serial") @@ -38,13 +40,18 @@ public class AggregateMessageDeliveryException extends MessageDeliveryException public AggregateMessageDeliveryException(Message undeliveredMessage, String description, List aggregatedExceptions) { + super(undeliveredMessage, description); this.initCause(aggregatedExceptions.get(0)); - this.aggregatedExceptions = aggregatedExceptions; + this.aggregatedExceptions = new ArrayList(aggregatedExceptions); } + /** + * Obtain a list aggregated target exceptions. + * @return the list of target exceptions + */ public List getAggregatedExceptions() { - return Collections.unmodifiableList(this.aggregatedExceptions); + return new ArrayList(this.aggregatedExceptions); } @Override diff --git a/spring-integration-core/src/main/java/org/springframework/integration/store/MessageGroupMetadata.java b/spring-integration-core/src/main/java/org/springframework/integration/store/MessageGroupMetadata.java index 2ea8394f3b..1930b98a6b 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/store/MessageGroupMetadata.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/store/MessageGroupMetadata.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 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. @@ -17,7 +17,6 @@ package org.springframework.integration.store; import java.io.Serializable; -import java.util.Collections; import java.util.Iterator; import java.util.LinkedList; import java.util.List; @@ -92,8 +91,13 @@ public class MessageGroupMetadata implements Serializable { return null; } + /** + * Obtain a {@link LinkedList} copy of the {@link #messageIds} + * stored in the group. + * @return the list of messages ids stored in the group + */ public List getMessageIds() { - return Collections.unmodifiableList(this.messageIds); + return new LinkedList(this.messageIds); } void complete() {