Search in sources :

Example 1 with Jackson2CodecSupport

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

the class ClientCodecConfigurerTests method objectMapperCustomization.

@Test
public void objectMapperCustomization() {
    ObjectMapper objectMapper = new ObjectMapper();
    this.configurer.defaultCodecs().configureDefaultCodec(codec -> {
        if (codec instanceof Jackson2CodecSupport) {
            ((Jackson2CodecSupport) codec).setObjectMapper(objectMapper);
        }
    });
    List<HttpMessageReader<?>> readers = this.configurer.getReaders();
    Jackson2JsonDecoder actualDecoder = findCodec(readers, Jackson2JsonDecoder.class);
    assertThat(actualDecoder.getObjectMapper()).isSameAs(objectMapper);
    List<HttpMessageWriter<?>> writers = this.configurer.getWriters();
    Jackson2JsonEncoder actualEncoder = findCodec(writers, Jackson2JsonEncoder.class);
    assertThat(actualEncoder.getObjectMapper()).isSameAs(objectMapper);
    MultipartHttpMessageWriter multipartWriter = findCodec(writers, MultipartHttpMessageWriter.class);
    actualEncoder = findCodec(multipartWriter.getPartWriters(), Jackson2JsonEncoder.class);
    assertThat(actualEncoder.getObjectMapper()).isSameAs(objectMapper);
}
Also used : 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) 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) Jackson2JsonDecoder(org.springframework.http.codec.json.Jackson2JsonDecoder) MultipartHttpMessageWriter(org.springframework.http.codec.multipart.MultipartHttpMessageWriter) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Jackson2CodecSupport(org.springframework.http.codec.json.Jackson2CodecSupport) Jackson2JsonEncoder(org.springframework.http.codec.json.Jackson2JsonEncoder) Test(org.junit.jupiter.api.Test)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Test (org.junit.jupiter.api.Test)1 DecoderHttpMessageReader (org.springframework.http.codec.DecoderHttpMessageReader)1 EncoderHttpMessageWriter (org.springframework.http.codec.EncoderHttpMessageWriter)1 FormHttpMessageReader (org.springframework.http.codec.FormHttpMessageReader)1 FormHttpMessageWriter (org.springframework.http.codec.FormHttpMessageWriter)1 HttpMessageReader (org.springframework.http.codec.HttpMessageReader)1 HttpMessageWriter (org.springframework.http.codec.HttpMessageWriter)1 ResourceHttpMessageReader (org.springframework.http.codec.ResourceHttpMessageReader)1 ResourceHttpMessageWriter (org.springframework.http.codec.ResourceHttpMessageWriter)1 ServerSentEventHttpMessageReader (org.springframework.http.codec.ServerSentEventHttpMessageReader)1 Jackson2CodecSupport (org.springframework.http.codec.json.Jackson2CodecSupport)1 Jackson2JsonDecoder (org.springframework.http.codec.json.Jackson2JsonDecoder)1 Jackson2JsonEncoder (org.springframework.http.codec.json.Jackson2JsonEncoder)1 MultipartHttpMessageWriter (org.springframework.http.codec.multipart.MultipartHttpMessageWriter)1 ProtobufHttpMessageWriter (org.springframework.http.codec.protobuf.ProtobufHttpMessageWriter)1