Fix BaseCodecConfigurer clone bug

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 gh-25149
This commit is contained in:
dlsrb6342
2020-05-28 19:15:25 +09:00
committed by Sam Brannen
parent a92f425529
commit fce972eec8
2 changed files with 21 additions and 5 deletions

View File

@@ -142,10 +142,10 @@ abstract class BaseCodecConfigurer implements CodecConfigurer {
* @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

View File

@@ -279,7 +279,7 @@ public class CodecConfigurerTests {
}
@Test
public void cloneCustomCodecs() {
public void cloneEmptyCustomCodecs() {
this.configurer.registerDefaults(false);
CodecConfigurer clone = this.configurer.clone();
@@ -294,6 +294,22 @@ public class CodecConfigurerTests {
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();