use of cn.taketoday.http.codec.CodecConfigurer in project today-infrastructure by TAKETODAY.
the class CodecConfigurerTests method cloneDefaultCodecs.
@Test
void cloneDefaultCodecs() {
CodecConfigurer clone = this.configurer.clone();
Jackson2JsonDecoder jacksonDecoder = new Jackson2JsonDecoder();
Jackson2JsonEncoder jacksonEncoder = new Jackson2JsonEncoder();
ProtobufDecoder protoDecoder = new ProtobufDecoder();
ProtobufEncoder protoEncoder = new ProtobufEncoder();
clone.defaultCodecs().jackson2JsonDecoder(jacksonDecoder);
clone.defaultCodecs().jackson2JsonEncoder(jacksonEncoder);
clone.defaultCodecs().protobufDecoder(protoDecoder);
clone.defaultCodecs().protobufEncoder(protoEncoder);
// Clone has the customized the customizations
List<Decoder<?>> decoders = clone.getReaders().stream().filter(reader -> reader instanceof DecoderHttpMessageReader).map(reader -> ((DecoderHttpMessageReader<?>) reader).getDecoder()).collect(Collectors.toList());
List<Encoder<?>> encoders = clone.getWriters().stream().filter(writer -> writer instanceof EncoderHttpMessageWriter).map(reader -> ((EncoderHttpMessageWriter<?>) reader).getEncoder()).collect(Collectors.toList());
// Original does not have the customizations
decoders = this.configurer.getReaders().stream().filter(reader -> reader instanceof DecoderHttpMessageReader).map(reader -> ((DecoderHttpMessageReader<?>) reader).getDecoder()).collect(Collectors.toList());
encoders = this.configurer.getWriters().stream().filter(writer -> writer instanceof EncoderHttpMessageWriter).map(reader -> ((EncoderHttpMessageWriter<?>) reader).getEncoder()).collect(Collectors.toList());
}
use of cn.taketoday.http.codec.CodecConfigurer in project today-framework by TAKETODAY.
the class CodecConfigurerTests method cloneDefaultCodecs.
@Test
void cloneDefaultCodecs() {
CodecConfigurer clone = this.configurer.clone();
Jackson2JsonDecoder jacksonDecoder = new Jackson2JsonDecoder();
Jackson2JsonEncoder jacksonEncoder = new Jackson2JsonEncoder();
ProtobufDecoder protoDecoder = new ProtobufDecoder();
ProtobufEncoder protoEncoder = new ProtobufEncoder();
clone.defaultCodecs().jackson2JsonDecoder(jacksonDecoder);
clone.defaultCodecs().jackson2JsonEncoder(jacksonEncoder);
clone.defaultCodecs().protobufDecoder(protoDecoder);
clone.defaultCodecs().protobufEncoder(protoEncoder);
// Clone has the customized the customizations
List<Decoder<?>> decoders = clone.getReaders().stream().filter(reader -> reader instanceof DecoderHttpMessageReader).map(reader -> ((DecoderHttpMessageReader<?>) reader).getDecoder()).collect(Collectors.toList());
List<Encoder<?>> encoders = clone.getWriters().stream().filter(writer -> writer instanceof EncoderHttpMessageWriter).map(reader -> ((EncoderHttpMessageWriter<?>) reader).getEncoder()).collect(Collectors.toList());
// Original does not have the customizations
decoders = this.configurer.getReaders().stream().filter(reader -> reader instanceof DecoderHttpMessageReader).map(reader -> ((DecoderHttpMessageReader<?>) reader).getDecoder()).collect(Collectors.toList());
encoders = this.configurer.getWriters().stream().filter(writer -> writer instanceof EncoderHttpMessageWriter).map(reader -> ((EncoderHttpMessageWriter<?>) reader).getEncoder()).collect(Collectors.toList());
}
use of cn.taketoday.http.codec.CodecConfigurer in project today-framework by TAKETODAY.
the class CodecConfigurerTests method cloneCustomCodecs.
@Test
void cloneCustomCodecs() {
this.configurer.registerDefaults(false);
assertThat(this.configurer.getReaders()).isEmpty();
assertThat(this.configurer.getWriters()).isEmpty();
this.configurer.customCodecs().register(new Jackson2JsonEncoder());
this.configurer.customCodecs().register(new Jackson2JsonDecoder());
this.configurer.customCodecs().register(new ServerSentEventHttpMessageReader());
this.configurer.customCodecs().register(new ServerSentEventHttpMessageWriter());
assertThat(this.configurer.getReaders()).hasSize(2);
assertThat(this.configurer.getWriters()).hasSize(2);
CodecConfigurer clone = this.configurer.clone();
assertThat(this.configurer.getReaders()).hasSize(2);
assertThat(this.configurer.getWriters()).hasSize(2);
assertThat(clone.getReaders()).hasSize(2);
assertThat(clone.getWriters()).hasSize(2);
}
use of cn.taketoday.http.codec.CodecConfigurer in project today-framework by TAKETODAY.
the class CodecConfigurerTests method cloneEmptyCustomCodecs.
@Test
void cloneEmptyCustomCodecs() {
this.configurer.registerDefaults(false);
assertThat(this.configurer.getReaders()).isEmpty();
assertThat(this.configurer.getWriters()).isEmpty();
CodecConfigurer clone = this.configurer.clone();
clone.customCodecs().register(new Jackson2JsonEncoder());
clone.customCodecs().register(new Jackson2JsonDecoder());
clone.customCodecs().register(new ServerSentEventHttpMessageReader());
clone.customCodecs().register(new ServerSentEventHttpMessageWriter());
assertThat(this.configurer.getReaders()).isEmpty();
assertThat(this.configurer.getWriters()).isEmpty();
assertThat(clone.getReaders()).hasSize(2);
assertThat(clone.getWriters()).hasSize(2);
}
use of cn.taketoday.http.codec.CodecConfigurer in project today-infrastructure by TAKETODAY.
the class CodecConfigurerTests method cloneCustomCodecs.
@Test
void cloneCustomCodecs() {
this.configurer.registerDefaults(false);
assertThat(this.configurer.getReaders()).isEmpty();
assertThat(this.configurer.getWriters()).isEmpty();
this.configurer.customCodecs().register(new Jackson2JsonEncoder());
this.configurer.customCodecs().register(new Jackson2JsonDecoder());
this.configurer.customCodecs().register(new ServerSentEventHttpMessageReader());
this.configurer.customCodecs().register(new ServerSentEventHttpMessageWriter());
assertThat(this.configurer.getReaders()).hasSize(2);
assertThat(this.configurer.getWriters()).hasSize(2);
CodecConfigurer clone = this.configurer.clone();
assertThat(this.configurer.getReaders()).hasSize(2);
assertThat(this.configurer.getWriters()).hasSize(2);
assertThat(clone.getReaders()).hasSize(2);
assertThat(clone.getWriters()).hasSize(2);
}
Aggregations