Search in sources :

Example 1 with ReactorObjectReader

use of reactivejson.ReactorObjectReader in project feign-reactive by kptfh.

the class JettyReactiveHttpResponse method body.

@Override
public Publisher<?> body() {
    ReactorObjectReader reactorObjectReader = new ReactorObjectReader(jsonFactory);
    Flux<ByteBuffer> content = directContent();
    if (returnActualClass == ByteBuffer.class) {
        return content;
    } else if (returnActualClass.isAssignableFrom(String.class) && returnPublisherType == Mono.class) {
        Charset charset = getCharset();
        return content.map(byteBuffer -> charset.decode(byteBuffer).toString());
    } else {
        if (returnPublisherType == Mono.class) {
            return reactorObjectReader.read(content, objectReader);
        } else if (returnPublisherType == Flux.class) {
            return reactorObjectReader.readElements(content, objectReader);
        } else {
            throw new IllegalArgumentException("Unknown returnPublisherType: " + returnPublisherType);
        }
    }
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) UTF_8(java.nio.charset.StandardCharsets.UTF_8) Optional.ofNullable(java.util.Optional.ofNullable) Publisher(org.reactivestreams.Publisher) JsonFactory(com.fasterxml.jackson.core.async_.JsonFactory) ReactorObjectReader(reactivejson.ReactorObjectReader) Mono(reactor.core.publisher.Mono) Collectors(java.util.stream.Collectors) ByteBuffer(java.nio.ByteBuffer) ObjectReader(com.fasterxml.jackson.databind.ObjectReader) ContentChunk(org.eclipse.jetty.reactive.client.ContentChunk) Flux(reactor.core.publisher.Flux) List(java.util.List) Charset(java.nio.charset.Charset) HttpField(org.eclipse.jetty.http.HttpField) Arrays.asList(java.util.Arrays.asList) ReactiveHttpResponse(reactivefeign.client.ReactiveHttpResponse) Map(java.util.Map) CONTENT_TYPE(org.eclipse.jetty.http.HttpHeader.CONTENT_TYPE) Response(org.eclipse.jetty.client.api.Response) Mono(reactor.core.publisher.Mono) Charset(java.nio.charset.Charset) ReactorObjectReader(reactivejson.ReactorObjectReader) ByteBuffer(java.nio.ByteBuffer)

Aggregations

JsonFactory (com.fasterxml.jackson.core.async_.JsonFactory)1 ObjectReader (com.fasterxml.jackson.databind.ObjectReader)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ByteBuffer (java.nio.ByteBuffer)1 Charset (java.nio.charset.Charset)1 UTF_8 (java.nio.charset.StandardCharsets.UTF_8)1 Arrays.asList (java.util.Arrays.asList)1 List (java.util.List)1 Map (java.util.Map)1 Optional.ofNullable (java.util.Optional.ofNullable)1 Collectors (java.util.stream.Collectors)1 Response (org.eclipse.jetty.client.api.Response)1 HttpField (org.eclipse.jetty.http.HttpField)1 CONTENT_TYPE (org.eclipse.jetty.http.HttpHeader.CONTENT_TYPE)1 ContentChunk (org.eclipse.jetty.reactive.client.ContentChunk)1 Publisher (org.reactivestreams.Publisher)1 ReactiveHttpResponse (reactivefeign.client.ReactiveHttpResponse)1 ReactorObjectReader (reactivejson.ReactorObjectReader)1 Flux (reactor.core.publisher.Flux)1 Mono (reactor.core.publisher.Mono)1