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 xcl(徐程林) committed Aug 16, 2020
1 parent 3a9c753 commit fdcb0d3
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 @@ -279,7 +279,7 @@ public void encoderDecoderOverrides() {
}

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

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

@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();
assertThat(from.getReaders().size()).isEqualTo(2);
assertThat(from.getWriters().size()).isEqualTo(2);
assertThat(clone.getReaders().size()).isEqualTo(2);
assertThat(clone.getWriters().size()).isEqualTo(2);
}

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

0 comments on commit fdcb0d3

Please sign in to comment.