Skip to content

Commit 539236d

Browse files
committed
Update the javadoc for the CompositeCodec class.
Change the `ClassUtils.findClosestMatch` `failOnTie` to true. In the past when finding the appropriate delegate(codec) for a object and their were multiple delegates available the first one was returned. The problem is it could return a different delegate on each launch of the `findDelegate`. Now with `failOnTie` set to true a `IllegalStateException` is returned. Remove deprecated constructor from CompositeCodec
1 parent 5aeee02 commit 539236d

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

spring-integration-core/src/main/java/org/springframework/integration/codec/CompositeCodec.java

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@
2727
import org.springframework.util.Assert;
2828

2929
/**
30-
* A Codec that can delegate to one out of many Codecs, each mapped to a class.
30+
* An implementation of {@link Codec} that combines multiple codecs into a single codec,
31+
* delegating encoding and decoding operations to the appropriate type-specific codec.
32+
* This implementation associates object types with their appropriate codecs while providing a fallback default codec
33+
* for unregistered types.
3134
* @author David Turanski
3235
* @author Glenn Renfro
3336
* @since 4.2
@@ -44,15 +47,6 @@ public CompositeCodec(Map<Class<?>, Codec> delegates, Codec defaultCodec) {
4447
this.delegates = new HashMap<>(delegates);
4548
}
4649

47-
/**
48-
* @deprecated since 7.0 in favor of {@link #CompositeCodec(Map, Codec)}.
49-
*/
50-
@Deprecated(since = "7.0", forRemoval = true)
51-
public CompositeCodec(Codec defaultCodec) {
52-
this.defaultCodec = defaultCodec;
53-
this.delegates = Map.of();
54-
}
55-
5650
@Override
5751
public void encode(Object object, OutputStream outputStream) throws IOException {
5852
Assert.notNull(object, "cannot encode a null object");
@@ -79,7 +73,7 @@ public <T> T decode(byte[] bytes, Class<T> type) throws IOException {
7973
}
8074

8175
private Codec findDelegate(Class<?> type) {
82-
Class<?> clazz = ClassUtils.findClosestMatch(type, this.delegates.keySet(), false);
76+
Class<?> clazz = ClassUtils.findClosestMatch(type, this.delegates.keySet(), true);
8377
return clazz == null ? this.defaultCodec : this.delegates.getOrDefault(clazz, this.defaultCodec);
8478
}
8579

0 commit comments

Comments
 (0)