Search in sources :

Example 1 with Jackson2SmileDecoder

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

the class BaseDefaultCodecs method initObjectReaders.

/**
 * Reset and initialize object readers.
 * @since 5.3.3
 */
protected void initObjectReaders() {
    this.objectReaders.clear();
    if (!this.registerDefaults) {
        return;
    }
    if (kotlinSerializationJsonPresent) {
        addCodec(this.objectReaders, new DecoderHttpMessageReader<>(getKotlinSerializationJsonDecoder()));
    }
    if (jackson2Present) {
        addCodec(this.objectReaders, new DecoderHttpMessageReader<>(getJackson2JsonDecoder()));
    }
    if (jackson2SmilePresent) {
        addCodec(this.objectReaders, new DecoderHttpMessageReader<>(this.jackson2SmileDecoder != null ? (Jackson2SmileDecoder) this.jackson2SmileDecoder : new Jackson2SmileDecoder()));
    }
    if (jaxb2Present && !shouldIgnoreXml) {
        addCodec(this.objectReaders, new DecoderHttpMessageReader<>(this.jaxb2Decoder != null ? (Jaxb2XmlDecoder) this.jaxb2Decoder : new Jaxb2XmlDecoder()));
    }
    // client vs server..
    extendObjectReaders(this.objectReaders);
}
Also used : Jaxb2XmlDecoder(org.springframework.http.codec.xml.Jaxb2XmlDecoder) Jackson2SmileDecoder(org.springframework.http.codec.json.Jackson2SmileDecoder)

Example 2 with Jackson2SmileDecoder

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

the class ClientCodecConfigurerTests method maxInMemorySize.

@Test
public void maxInMemorySize() {
    int size = 99;
    this.configurer.defaultCodecs().maxInMemorySize(size);
    List<HttpMessageReader<?>> readers = this.configurer.getReaders();
    assertThat(readers.size()).isEqualTo(14);
    assertThat(((ByteArrayDecoder) getNextDecoder(readers)).getMaxInMemorySize()).isEqualTo(size);
    assertThat(((ByteBufferDecoder) getNextDecoder(readers)).getMaxInMemorySize()).isEqualTo(size);
    assertThat(((DataBufferDecoder) getNextDecoder(readers)).getMaxInMemorySize()).isEqualTo(size);
    assertThat(((NettyByteBufDecoder) getNextDecoder(readers)).getMaxInMemorySize()).isEqualTo(size);
    assertThat(((ResourceDecoder) getNextDecoder(readers)).getMaxInMemorySize()).isEqualTo(size);
    assertThat(((StringDecoder) getNextDecoder(readers)).getMaxInMemorySize()).isEqualTo(size);
    assertThat(((ProtobufDecoder) getNextDecoder(readers)).getMaxMessageSize()).isEqualTo(size);
    assertThat(((FormHttpMessageReader) nextReader(readers)).getMaxInMemorySize()).isEqualTo(size);
    assertThat(((KotlinSerializationJsonDecoder) getNextDecoder(readers)).getMaxInMemorySize()).isEqualTo(size);
    assertThat(((Jackson2JsonDecoder) getNextDecoder(readers)).getMaxInMemorySize()).isEqualTo(size);
    assertThat(((Jackson2SmileDecoder) getNextDecoder(readers)).getMaxInMemorySize()).isEqualTo(size);
    assertThat(((Jaxb2XmlDecoder) getNextDecoder(readers)).getMaxInMemorySize()).isEqualTo(size);
    ServerSentEventHttpMessageReader reader = (ServerSentEventHttpMessageReader) nextReader(readers);
    assertThat(reader.getMaxInMemorySize()).isEqualTo(size);
    assertThat(((Jackson2JsonDecoder) reader.getDecoder()).getMaxInMemorySize()).isEqualTo(size);
    assertThat(((StringDecoder) getNextDecoder(readers)).getMaxInMemorySize()).isEqualTo(size);
}
Also used : Jackson2JsonDecoder(org.springframework.http.codec.json.Jackson2JsonDecoder) ProtobufDecoder(org.springframework.http.codec.protobuf.ProtobufDecoder) Jaxb2XmlDecoder(org.springframework.http.codec.xml.Jaxb2XmlDecoder) StringDecoder(org.springframework.core.codec.StringDecoder) ResourceDecoder(org.springframework.core.codec.ResourceDecoder) ByteBufferDecoder(org.springframework.core.codec.ByteBufferDecoder) ServerSentEventHttpMessageReader(org.springframework.http.codec.ServerSentEventHttpMessageReader) DecoderHttpMessageReader(org.springframework.http.codec.DecoderHttpMessageReader) FormHttpMessageReader(org.springframework.http.codec.FormHttpMessageReader) HttpMessageReader(org.springframework.http.codec.HttpMessageReader) ResourceHttpMessageReader(org.springframework.http.codec.ResourceHttpMessageReader) FormHttpMessageReader(org.springframework.http.codec.FormHttpMessageReader) NettyByteBufDecoder(org.springframework.core.codec.NettyByteBufDecoder) KotlinSerializationJsonDecoder(org.springframework.http.codec.json.KotlinSerializationJsonDecoder) ServerSentEventHttpMessageReader(org.springframework.http.codec.ServerSentEventHttpMessageReader) DataBufferDecoder(org.springframework.core.codec.DataBufferDecoder) ByteArrayDecoder(org.springframework.core.codec.ByteArrayDecoder) Jackson2SmileDecoder(org.springframework.http.codec.json.Jackson2SmileDecoder) Test(org.junit.jupiter.api.Test)

Example 3 with Jackson2SmileDecoder

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

the class ServerCodecConfigurerTests method maxInMemorySize.

@Test
public void maxInMemorySize() {
    int size = 99;
    this.configurer.defaultCodecs().maxInMemorySize(size);
    List<HttpMessageReader<?>> readers = this.configurer.getReaders();
    assertThat(((ByteArrayDecoder) getNextDecoder(readers)).getMaxInMemorySize()).isEqualTo(size);
    assertThat(((ByteBufferDecoder) getNextDecoder(readers)).getMaxInMemorySize()).isEqualTo(size);
    assertThat(((DataBufferDecoder) getNextDecoder(readers)).getMaxInMemorySize()).isEqualTo(size);
    assertThat(((NettyByteBufDecoder) getNextDecoder(readers)).getMaxInMemorySize()).isEqualTo(size);
    assertThat(((ResourceDecoder) getNextDecoder(readers)).getMaxInMemorySize()).isEqualTo(size);
    assertThat(((StringDecoder) getNextDecoder(readers)).getMaxInMemorySize()).isEqualTo(size);
    assertThat(((ProtobufDecoder) getNextDecoder(readers)).getMaxMessageSize()).isEqualTo(size);
    assertThat(((FormHttpMessageReader) nextReader(readers)).getMaxInMemorySize()).isEqualTo(size);
    assertThat(((DefaultPartHttpMessageReader) nextReader(readers)).getMaxInMemorySize()).isEqualTo(size);
    MultipartHttpMessageReader multipartReader = (MultipartHttpMessageReader) nextReader(readers);
    DefaultPartHttpMessageReader reader = (DefaultPartHttpMessageReader) multipartReader.getPartReader();
    assertThat((reader).getMaxInMemorySize()).isEqualTo(size);
    assertThat(((KotlinSerializationJsonDecoder) getNextDecoder(readers)).getMaxInMemorySize()).isEqualTo(size);
    assertThat(((Jackson2JsonDecoder) getNextDecoder(readers)).getMaxInMemorySize()).isEqualTo(size);
    assertThat(((Jackson2SmileDecoder) getNextDecoder(readers)).getMaxInMemorySize()).isEqualTo(size);
    assertThat(((Jaxb2XmlDecoder) getNextDecoder(readers)).getMaxInMemorySize()).isEqualTo(size);
    assertThat(((StringDecoder) getNextDecoder(readers)).getMaxInMemorySize()).isEqualTo(size);
}
Also used : MultipartHttpMessageReader(org.springframework.http.codec.multipart.MultipartHttpMessageReader) DefaultPartHttpMessageReader(org.springframework.http.codec.multipart.DefaultPartHttpMessageReader) Jackson2JsonDecoder(org.springframework.http.codec.json.Jackson2JsonDecoder) ProtobufDecoder(org.springframework.http.codec.protobuf.ProtobufDecoder) Jaxb2XmlDecoder(org.springframework.http.codec.xml.Jaxb2XmlDecoder) StringDecoder(org.springframework.core.codec.StringDecoder) ResourceDecoder(org.springframework.core.codec.ResourceDecoder) ByteBufferDecoder(org.springframework.core.codec.ByteBufferDecoder) DefaultPartHttpMessageReader(org.springframework.http.codec.multipart.DefaultPartHttpMessageReader) DecoderHttpMessageReader(org.springframework.http.codec.DecoderHttpMessageReader) FormHttpMessageReader(org.springframework.http.codec.FormHttpMessageReader) HttpMessageReader(org.springframework.http.codec.HttpMessageReader) ResourceHttpMessageReader(org.springframework.http.codec.ResourceHttpMessageReader) MultipartHttpMessageReader(org.springframework.http.codec.multipart.MultipartHttpMessageReader) FormHttpMessageReader(org.springframework.http.codec.FormHttpMessageReader) NettyByteBufDecoder(org.springframework.core.codec.NettyByteBufDecoder) KotlinSerializationJsonDecoder(org.springframework.http.codec.json.KotlinSerializationJsonDecoder) DataBufferDecoder(org.springframework.core.codec.DataBufferDecoder) ByteArrayDecoder(org.springframework.core.codec.ByteArrayDecoder) Jackson2SmileDecoder(org.springframework.http.codec.json.Jackson2SmileDecoder) Test(org.junit.jupiter.api.Test)

Example 4 with Jackson2SmileDecoder

use of org.springframework.http.codec.json.Jackson2SmileDecoder 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

Jackson2SmileDecoder (org.springframework.http.codec.json.Jackson2SmileDecoder)4 Jaxb2XmlDecoder (org.springframework.http.codec.xml.Jaxb2XmlDecoder)4 Test (org.junit.jupiter.api.Test)3 Jackson2JsonDecoder (org.springframework.http.codec.json.Jackson2JsonDecoder)3 ProtobufDecoder (org.springframework.http.codec.protobuf.ProtobufDecoder)3 ByteArrayDecoder (org.springframework.core.codec.ByteArrayDecoder)2 ByteBufferDecoder (org.springframework.core.codec.ByteBufferDecoder)2 DataBufferDecoder (org.springframework.core.codec.DataBufferDecoder)2 NettyByteBufDecoder (org.springframework.core.codec.NettyByteBufDecoder)2 ResourceDecoder (org.springframework.core.codec.ResourceDecoder)2 StringDecoder (org.springframework.core.codec.StringDecoder)2 DecoderHttpMessageReader (org.springframework.http.codec.DecoderHttpMessageReader)2 FormHttpMessageReader (org.springframework.http.codec.FormHttpMessageReader)2 HttpMessageReader (org.springframework.http.codec.HttpMessageReader)2 ResourceHttpMessageReader (org.springframework.http.codec.ResourceHttpMessageReader)2 KotlinSerializationJsonDecoder (org.springframework.http.codec.json.KotlinSerializationJsonDecoder)2 ServerSentEventHttpMessageReader (org.springframework.http.codec.ServerSentEventHttpMessageReader)1 Jackson2JsonEncoder (org.springframework.http.codec.json.Jackson2JsonEncoder)1 Jackson2SmileEncoder (org.springframework.http.codec.json.Jackson2SmileEncoder)1 DefaultPartHttpMessageReader (org.springframework.http.codec.multipart.DefaultPartHttpMessageReader)1