Search in sources :

Example 26 with Jackson2JsonEncoder

use of cn.taketoday.http.codec.json.Jackson2JsonEncoder 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);
}
Also used : ServerSentEventHttpMessageReader(cn.taketoday.http.codec.ServerSentEventHttpMessageReader) Jackson2JsonDecoder(cn.taketoday.http.codec.json.Jackson2JsonDecoder) ServerSentEventHttpMessageWriter(cn.taketoday.http.codec.ServerSentEventHttpMessageWriter) Jackson2JsonEncoder(cn.taketoday.http.codec.json.Jackson2JsonEncoder) CodecConfigurer(cn.taketoday.http.codec.CodecConfigurer) Test(org.junit.jupiter.api.Test)

Example 27 with Jackson2JsonEncoder

use of cn.taketoday.http.codec.json.Jackson2JsonEncoder in project today-infrastructure by TAKETODAY.

the class CodecConfigurerTests method encoderDecoderOverrides.

@Test
void encoderDecoderOverrides() {
    Jackson2JsonDecoder jacksonDecoder = new Jackson2JsonDecoder();
    Jackson2JsonEncoder jacksonEncoder = new Jackson2JsonEncoder();
    Jackson2SmileDecoder smileDecoder = new Jackson2SmileDecoder();
    Jackson2SmileEncoder smileEncoder = new Jackson2SmileEncoder();
    ProtobufDecoder protobufDecoder = new ProtobufDecoder(ExtensionRegistry.newInstance());
    ProtobufEncoder protobufEncoder = new ProtobufEncoder();
    this.configurer.defaultCodecs().jackson2JsonDecoder(jacksonDecoder);
    this.configurer.defaultCodecs().jackson2JsonEncoder(jacksonEncoder);
    this.configurer.defaultCodecs().jackson2SmileDecoder(smileDecoder);
    this.configurer.defaultCodecs().jackson2SmileEncoder(smileEncoder);
    this.configurer.defaultCodecs().protobufDecoder(protobufDecoder);
    this.configurer.defaultCodecs().protobufEncoder(protobufEncoder);
    assertDecoderInstance(jacksonDecoder);
    assertDecoderInstance(smileDecoder);
    assertDecoderInstance(protobufDecoder);
    assertEncoderInstance(jacksonEncoder);
    assertEncoderInstance(smileEncoder);
    assertEncoderInstance(protobufEncoder);
}
Also used : ProtobufEncoder(cn.taketoday.http.codec.protobuf.ProtobufEncoder) Jackson2JsonDecoder(cn.taketoday.http.codec.json.Jackson2JsonDecoder) Jackson2SmileEncoder(cn.taketoday.http.codec.json.Jackson2SmileEncoder) ProtobufDecoder(cn.taketoday.http.codec.protobuf.ProtobufDecoder) Jackson2JsonEncoder(cn.taketoday.http.codec.json.Jackson2JsonEncoder) Jackson2SmileDecoder(cn.taketoday.http.codec.json.Jackson2SmileDecoder) Test(org.junit.jupiter.api.Test)

Example 28 with Jackson2JsonEncoder

use of cn.taketoday.http.codec.json.Jackson2JsonEncoder in project today-infrastructure 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);
}
Also used : ServerSentEventHttpMessageReader(cn.taketoday.http.codec.ServerSentEventHttpMessageReader) Jackson2JsonDecoder(cn.taketoday.http.codec.json.Jackson2JsonDecoder) ServerSentEventHttpMessageWriter(cn.taketoday.http.codec.ServerSentEventHttpMessageWriter) CodecConfigurer(cn.taketoday.http.codec.CodecConfigurer) Jackson2JsonEncoder(cn.taketoday.http.codec.json.Jackson2JsonEncoder) Test(org.junit.jupiter.api.Test)

Aggregations

Jackson2JsonEncoder (cn.taketoday.http.codec.json.Jackson2JsonEncoder)28 Test (org.junit.jupiter.api.Test)24 EncoderHttpMessageWriter (cn.taketoday.http.codec.EncoderHttpMessageWriter)14 Jackson2JsonDecoder (cn.taketoday.http.codec.json.Jackson2JsonDecoder)14 HttpMessageWriter (cn.taketoday.http.codec.HttpMessageWriter)12 ResourceHttpMessageWriter (cn.taketoday.http.codec.ResourceHttpMessageWriter)12 ServerSentEventHttpMessageWriter (cn.taketoday.http.codec.ServerSentEventHttpMessageWriter)12 ServerSentEventHttpMessageReader (cn.taketoday.http.codec.ServerSentEventHttpMessageReader)10 ProtobufHttpMessageWriter (cn.taketoday.http.codec.protobuf.ProtobufHttpMessageWriter)10 DecoderHttpMessageReader (cn.taketoday.http.codec.DecoderHttpMessageReader)8 FormHttpMessageReader (cn.taketoday.http.codec.FormHttpMessageReader)8 FormHttpMessageWriter (cn.taketoday.http.codec.FormHttpMessageWriter)8 HttpMessageReader (cn.taketoday.http.codec.HttpMessageReader)8 ResourceHttpMessageReader (cn.taketoday.http.codec.ResourceHttpMessageReader)8 MultipartHttpMessageWriter (cn.taketoday.http.codec.multipart.MultipartHttpMessageWriter)8 CodecConfigurer (cn.taketoday.http.codec.CodecConfigurer)6 PartEventHttpMessageWriter (cn.taketoday.http.codec.multipart.PartEventHttpMessageWriter)6 ByteBufferEncoder (cn.taketoday.core.codec.ByteBufferEncoder)4 Jackson2SmileDecoder (cn.taketoday.http.codec.json.Jackson2SmileDecoder)4 Jackson2SmileEncoder (cn.taketoday.http.codec.json.Jackson2SmileEncoder)4