Search in sources :

Example 1 with Jackson2SmileEncoder

use of org.springframework.http.codec.json.Jackson2SmileEncoder in project spring-framework by spring-projects.

the class ClientCodecConfigurerTests method clonedConfigurer.

@Test
public void clonedConfigurer() {
    ClientCodecConfigurer clone = this.configurer.clone();
    Jackson2JsonDecoder jackson2Decoder = new Jackson2JsonDecoder();
    clone.defaultCodecs().serverSentEventDecoder(jackson2Decoder);
    clone.defaultCodecs().multipartCodecs().encoder(new Jackson2SmileEncoder());
    clone.defaultCodecs().multipartCodecs().writer(new ResourceHttpMessageWriter());
    // Clone has the customizations
    Decoder<?> sseDecoder = findCodec(clone.getReaders(), ServerSentEventHttpMessageReader.class).getDecoder();
    List<HttpMessageWriter<?>> writers = findCodec(clone.getWriters(), MultipartHttpMessageWriter.class).getPartWriters();
    assertThat(sseDecoder).isSameAs(jackson2Decoder);
    assertThat(writers).hasSize(2);
    // Original does not have the customizations
    sseDecoder = findCodec(this.configurer.getReaders(), ServerSentEventHttpMessageReader.class).getDecoder();
    writers = findCodec(this.configurer.getWriters(), MultipartHttpMessageWriter.class).getPartWriters();
    assertThat(sseDecoder).isNotSameAs(jackson2Decoder);
    assertThat(writers).hasSize(12);
}
Also used : ServerSentEventHttpMessageReader(org.springframework.http.codec.ServerSentEventHttpMessageReader) FormHttpMessageWriter(org.springframework.http.codec.FormHttpMessageWriter) MultipartHttpMessageWriter(org.springframework.http.codec.multipart.MultipartHttpMessageWriter) ResourceHttpMessageWriter(org.springframework.http.codec.ResourceHttpMessageWriter) EncoderHttpMessageWriter(org.springframework.http.codec.EncoderHttpMessageWriter) ProtobufHttpMessageWriter(org.springframework.http.codec.protobuf.ProtobufHttpMessageWriter) HttpMessageWriter(org.springframework.http.codec.HttpMessageWriter) ClientCodecConfigurer(org.springframework.http.codec.ClientCodecConfigurer) Jackson2JsonDecoder(org.springframework.http.codec.json.Jackson2JsonDecoder) Jackson2SmileEncoder(org.springframework.http.codec.json.Jackson2SmileEncoder) ResourceHttpMessageWriter(org.springframework.http.codec.ResourceHttpMessageWriter) MultipartHttpMessageWriter(org.springframework.http.codec.multipart.MultipartHttpMessageWriter) Test(org.junit.jupiter.api.Test)

Example 2 with Jackson2SmileEncoder

use of org.springframework.http.codec.json.Jackson2SmileEncoder in project spring-framework by spring-projects.

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();
    Jaxb2XmlEncoder jaxb2Encoder = new Jaxb2XmlEncoder();
    Jaxb2XmlDecoder jaxb2Decoder = new Jaxb2XmlDecoder();
    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);
    this.configurer.defaultCodecs().jaxb2Decoder(jaxb2Decoder);
    this.configurer.defaultCodecs().jaxb2Encoder(jaxb2Encoder);
    assertDecoderInstance(jacksonDecoder);
    assertDecoderInstance(smileDecoder);
    assertDecoderInstance(protobufDecoder);
    assertDecoderInstance(jaxb2Decoder);
    assertEncoderInstance(jacksonEncoder);
    assertEncoderInstance(smileEncoder);
    assertEncoderInstance(protobufEncoder);
    assertEncoderInstance(jaxb2Encoder);
}
Also used : ProtobufEncoder(org.springframework.http.codec.protobuf.ProtobufEncoder) Jackson2JsonDecoder(org.springframework.http.codec.json.Jackson2JsonDecoder) Jackson2SmileEncoder(org.springframework.http.codec.json.Jackson2SmileEncoder) ProtobufDecoder(org.springframework.http.codec.protobuf.ProtobufDecoder) Jaxb2XmlDecoder(org.springframework.http.codec.xml.Jaxb2XmlDecoder) Jaxb2XmlEncoder(org.springframework.http.codec.xml.Jaxb2XmlEncoder) Jackson2JsonEncoder(org.springframework.http.codec.json.Jackson2JsonEncoder) Jackson2SmileDecoder(org.springframework.http.codec.json.Jackson2SmileDecoder) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)2 Jackson2JsonDecoder (org.springframework.http.codec.json.Jackson2JsonDecoder)2 Jackson2SmileEncoder (org.springframework.http.codec.json.Jackson2SmileEncoder)2 ClientCodecConfigurer (org.springframework.http.codec.ClientCodecConfigurer)1 EncoderHttpMessageWriter (org.springframework.http.codec.EncoderHttpMessageWriter)1 FormHttpMessageWriter (org.springframework.http.codec.FormHttpMessageWriter)1 HttpMessageWriter (org.springframework.http.codec.HttpMessageWriter)1 ResourceHttpMessageWriter (org.springframework.http.codec.ResourceHttpMessageWriter)1 ServerSentEventHttpMessageReader (org.springframework.http.codec.ServerSentEventHttpMessageReader)1 Jackson2JsonEncoder (org.springframework.http.codec.json.Jackson2JsonEncoder)1 Jackson2SmileDecoder (org.springframework.http.codec.json.Jackson2SmileDecoder)1 MultipartHttpMessageWriter (org.springframework.http.codec.multipart.MultipartHttpMessageWriter)1 ProtobufDecoder (org.springframework.http.codec.protobuf.ProtobufDecoder)1 ProtobufEncoder (org.springframework.http.codec.protobuf.ProtobufEncoder)1 ProtobufHttpMessageWriter (org.springframework.http.codec.protobuf.ProtobufHttpMessageWriter)1 Jaxb2XmlDecoder (org.springframework.http.codec.xml.Jaxb2XmlDecoder)1 Jaxb2XmlEncoder (org.springframework.http.codec.xml.Jaxb2XmlEncoder)1