Skip to content

Commit

Permalink
Fix BaseCodecConfigurer clone bug
Browse files Browse the repository at this point in the history
Prior to this commit, ExchangeStrategies custom codec's reader and
writer were not registered due to a bug in BaseCodecConfigurer.

This commit fixes this by correcting the implementation of the
DefaultCustomCodecs constructor used within BaseCodecConfigurer.

Closes spring-projectsgh-25149
  • Loading branch information
dlsrb6342 authored and zx20110729 committed Feb 18, 2022
1 parent 53774df commit 062e891
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
Expand Up @@ -142,10 +142,10 @@ protected static final class DefaultCustomCodecs implements CustomCodecs {
* @since 5.1.12
*/
DefaultCustomCodecs(DefaultCustomCodecs other) {
other.typedReaders.putAll(this.typedReaders);
other.typedWriters.putAll(this.typedWriters);
other.objectReaders.putAll(this.objectReaders);
other.objectWriters.putAll(this.objectWriters);
this.typedReaders.putAll(other.typedReaders);
this.typedWriters.putAll(other.typedWriters);
this.objectReaders.putAll(other.objectReaders);
this.objectWriters.putAll(other.objectWriters);
}

@Override
Expand Down
Expand Up @@ -273,7 +273,7 @@ public void encoderDecoderOverrides() {
}

@Test
public void cloneCustomCodecs() {
public void cloneEmptyCustomCodecs() {
this.configurer.registerDefaults(false);
CodecConfigurer clone = this.configurer.clone();

Expand All @@ -288,6 +288,22 @@ public void cloneCustomCodecs() {
assertEquals(2, clone.getWriters().size());
}

@Test
public void cloneCustomCodecs() {
CodecConfigurer from = new TestCodecConfigurer();
from.registerDefaults(false);
from.customCodecs().register(new Jackson2JsonEncoder());
from.customCodecs().register(new Jackson2JsonDecoder());
from.customCodecs().register(new ServerSentEventHttpMessageReader());
from.customCodecs().register(new ServerSentEventHttpMessageWriter());

CodecConfigurer clone = from.clone();
assertEquals(2, from.getReaders().size());
assertEquals(2, from.getWriters().size());
assertEquals(2, clone.getReaders().size());
assertEquals(2, clone.getWriters().size());
}

@Test
public void cloneDefaultCodecs() {
CodecConfigurer clone = this.configurer.clone();
Expand Down

0 comments on commit 062e891

Please sign in to comment.