Search in sources :

Example 1 with Jackson2JsonDecoder

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

the class WebFluxConfigurationSupport method addDefaultHttpMessageReaders.

/**
	 * Adds default converters that sub-classes can call from
	 * {@link #configureMessageReaders(List)} for {@code byte[]},
	 * {@code ByteBuffer}, {@code String}, {@code Resource}, JAXB2, and Jackson
	 * (if present on the classpath).
	 */
protected final void addDefaultHttpMessageReaders(List<HttpMessageReader<?>> readers) {
    readers.add(new DecoderHttpMessageReader<>(new ByteArrayDecoder()));
    readers.add(new DecoderHttpMessageReader<>(new ByteBufferDecoder()));
    readers.add(new DecoderHttpMessageReader<>(new DataBufferDecoder()));
    readers.add(new DecoderHttpMessageReader<>(new StringDecoder()));
    readers.add(new DecoderHttpMessageReader<>(new ResourceDecoder()));
    if (jaxb2Present) {
        readers.add(new DecoderHttpMessageReader<>(new Jaxb2XmlDecoder()));
    }
    if (jackson2Present) {
        readers.add(new Jackson2ServerHttpMessageReader(new DecoderHttpMessageReader<>(new Jackson2JsonDecoder())));
    }
}
Also used : DecoderHttpMessageReader(org.springframework.http.codec.DecoderHttpMessageReader) Jackson2JsonDecoder(org.springframework.http.codec.json.Jackson2JsonDecoder) DataBufferDecoder(org.springframework.core.codec.DataBufferDecoder) 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) ByteArrayDecoder(org.springframework.core.codec.ByteArrayDecoder) Jackson2ServerHttpMessageReader(org.springframework.http.codec.Jackson2ServerHttpMessageReader)

Example 2 with Jackson2JsonDecoder

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

the class DefaultExchangeStrategiesBuilder method defaultReaders.

private void defaultReaders() {
    messageReader(new DecoderHttpMessageReader<>(new ByteArrayDecoder()));
    messageReader(new DecoderHttpMessageReader<>(new ByteBufferDecoder()));
    messageReader(new ServerSentEventHttpMessageReader(sseDecoders()));
    messageReader(new DecoderHttpMessageReader<>(new StringDecoder(false)));
    if (jaxb2Present) {
        messageReader(new DecoderHttpMessageReader<>(new Jaxb2XmlDecoder()));
    }
    if (jackson2Present) {
        messageReader(new DecoderHttpMessageReader<>(new Jackson2JsonDecoder()));
    }
}
Also used : ServerSentEventHttpMessageReader(org.springframework.http.codec.ServerSentEventHttpMessageReader) Jackson2JsonDecoder(org.springframework.http.codec.json.Jackson2JsonDecoder) Jaxb2XmlDecoder(org.springframework.http.codec.xml.Jaxb2XmlDecoder) StringDecoder(org.springframework.core.codec.StringDecoder) ByteBufferDecoder(org.springframework.core.codec.ByteBufferDecoder) ByteArrayDecoder(org.springframework.core.codec.ByteArrayDecoder)

Example 3 with Jackson2JsonDecoder

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

the class DefaultHandlerStrategiesBuilder method defaultConfiguration.

public void defaultConfiguration() {
    messageReader(new DecoderHttpMessageReader<>(new ByteArrayDecoder()));
    messageReader(new DecoderHttpMessageReader<>(new ByteBufferDecoder()));
    messageReader(new DecoderHttpMessageReader<>(new StringDecoder()));
    messageReader(new FormHttpMessageReader());
    messageWriter(new EncoderHttpMessageWriter<>(new ByteArrayEncoder()));
    messageWriter(new EncoderHttpMessageWriter<>(new ByteBufferEncoder()));
    messageWriter(new EncoderHttpMessageWriter<>(new CharSequenceEncoder()));
    messageWriter(new ResourceHttpMessageWriter());
    if (jaxb2Present) {
        messageReader(new DecoderHttpMessageReader<>(new Jaxb2XmlDecoder()));
        messageWriter(new EncoderHttpMessageWriter<>(new Jaxb2XmlEncoder()));
    }
    if (jackson2Present) {
        messageReader(new DecoderHttpMessageReader<>(new Jackson2JsonDecoder()));
        Jackson2JsonEncoder jsonEncoder = new Jackson2JsonEncoder();
        messageWriter(new Jackson2ServerHttpMessageWriter(jsonEncoder));
        messageWriter(new ServerSentEventHttpMessageWriter(Collections.singletonList(jsonEncoder)));
    } else {
        messageWriter(new ServerSentEventHttpMessageWriter());
    }
    localeResolver(DEFAULT_LOCALE_RESOLVER);
}
Also used : ByteBufferEncoder(org.springframework.core.codec.ByteBufferEncoder) ByteArrayEncoder(org.springframework.core.codec.ByteArrayEncoder) Jackson2JsonDecoder(org.springframework.http.codec.json.Jackson2JsonDecoder) Jaxb2XmlDecoder(org.springframework.http.codec.xml.Jaxb2XmlDecoder) ServerSentEventHttpMessageWriter(org.springframework.http.codec.ServerSentEventHttpMessageWriter) StringDecoder(org.springframework.core.codec.StringDecoder) ByteBufferDecoder(org.springframework.core.codec.ByteBufferDecoder) Jaxb2XmlEncoder(org.springframework.http.codec.xml.Jaxb2XmlEncoder) Jackson2JsonEncoder(org.springframework.http.codec.json.Jackson2JsonEncoder) FormHttpMessageReader(org.springframework.http.codec.FormHttpMessageReader) Jackson2ServerHttpMessageWriter(org.springframework.http.codec.Jackson2ServerHttpMessageWriter) ResourceHttpMessageWriter(org.springframework.http.codec.ResourceHttpMessageWriter) CharSequenceEncoder(org.springframework.core.codec.CharSequenceEncoder) ByteArrayDecoder(org.springframework.core.codec.ByteArrayDecoder)

Example 4 with Jackson2JsonDecoder

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

the class BodyExtractorsTests method createContext.

@Before
public void createContext() {
    final List<HttpMessageReader<?>> messageReaders = new ArrayList<>();
    messageReaders.add(new DecoderHttpMessageReader<>(new ByteBufferDecoder()));
    messageReaders.add(new DecoderHttpMessageReader<>(new StringDecoder()));
    messageReaders.add(new DecoderHttpMessageReader<>(new Jaxb2XmlDecoder()));
    messageReaders.add(new DecoderHttpMessageReader<>(new Jackson2JsonDecoder()));
    messageReaders.add(new FormHttpMessageReader());
    this.context = new BodyExtractor.Context() {

        @Override
        public Supplier<Stream<HttpMessageReader<?>>> messageReaders() {
            return messageReaders::stream;
        }

        @Override
        public Map<String, Object> hints() {
            return hints;
        }
    };
    this.hints = new HashMap<String, Object>();
}
Also used : Jackson2JsonDecoder(org.springframework.http.codec.json.Jackson2JsonDecoder) ArrayList(java.util.ArrayList) Jaxb2XmlDecoder(org.springframework.http.codec.xml.Jaxb2XmlDecoder) StringDecoder(org.springframework.core.codec.StringDecoder) ByteBufferDecoder(org.springframework.core.codec.ByteBufferDecoder) FormHttpMessageReader(org.springframework.http.codec.FormHttpMessageReader) HttpMessageReader(org.springframework.http.codec.HttpMessageReader) DecoderHttpMessageReader(org.springframework.http.codec.DecoderHttpMessageReader) FormHttpMessageReader(org.springframework.http.codec.FormHttpMessageReader) Supplier(java.util.function.Supplier) HashMap(java.util.HashMap) Map(java.util.Map) MultiValueMap(org.springframework.util.MultiValueMap) Before(org.junit.Before)

Aggregations

ByteBufferDecoder (org.springframework.core.codec.ByteBufferDecoder)4 StringDecoder (org.springframework.core.codec.StringDecoder)4 Jackson2JsonDecoder (org.springframework.http.codec.json.Jackson2JsonDecoder)4 Jaxb2XmlDecoder (org.springframework.http.codec.xml.Jaxb2XmlDecoder)4 ByteArrayDecoder (org.springframework.core.codec.ByteArrayDecoder)3 DecoderHttpMessageReader (org.springframework.http.codec.DecoderHttpMessageReader)2 FormHttpMessageReader (org.springframework.http.codec.FormHttpMessageReader)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Supplier (java.util.function.Supplier)1 Before (org.junit.Before)1 ByteArrayEncoder (org.springframework.core.codec.ByteArrayEncoder)1 ByteBufferEncoder (org.springframework.core.codec.ByteBufferEncoder)1 CharSequenceEncoder (org.springframework.core.codec.CharSequenceEncoder)1 DataBufferDecoder (org.springframework.core.codec.DataBufferDecoder)1 ResourceDecoder (org.springframework.core.codec.ResourceDecoder)1 HttpMessageReader (org.springframework.http.codec.HttpMessageReader)1 Jackson2ServerHttpMessageReader (org.springframework.http.codec.Jackson2ServerHttpMessageReader)1 Jackson2ServerHttpMessageWriter (org.springframework.http.codec.Jackson2ServerHttpMessageWriter)1