@API(status=STABLE) public final class Streams extends Object
StreamConverter with Riptide
(using streamConverter(ObjectMapper) and declare a route for your stream that is calling a the stream consumer
as follows:
try (Http http = Http.builder().baseUrl("https://api.github.com").converter(streamConverter()).build()) {
http.get("/repos/{org}/{repo}/contributors", "zalando", "riptide")
.accept(MediaType.APPLICATION_JSON)
.dispatch(series(),
on(SUCCESSFUL).call(streamOf(User.class),
forEach(user -> println(user.login + " (" + user.contributions + ")"))))
.get();
}
Note: The stream converter is an replacement to the default spring JSON converter that does not support
streaming, and thus should be not registered together with it.| Modifier and Type | Field and Description |
|---|---|
static org.springframework.http.MediaType |
APPLICATION_JSON_SEQ |
static org.springframework.http.MediaType |
APPLICATION_STREAM_JSON |
static org.springframework.http.MediaType |
APPLICATION_X_JSON_STREAM |
| Modifier and Type | Method and Description |
|---|---|
static <I,X extends Throwable> |
forEach(org.zalando.fauxpas.ThrowingConsumer<I,X> consumer)
Creates
stream consumer for given element consumer. |
static <T> org.zalando.riptide.stream.StreamConverter<T> |
streamConverter()
Create default stream converter.
|
static <T> org.zalando.riptide.stream.StreamConverter<T> |
streamConverter(com.fasterxml.jackson.databind.ObjectMapper mapper)
Create stream converter with custom
object mapper. |
static <T> org.zalando.riptide.stream.StreamConverter<T> |
streamConverter(com.fasterxml.jackson.databind.ObjectMapper mapper,
List<org.springframework.http.MediaType> supportedMediaTypes)
Create stream converter with custom
object mapper, and custom list of
supported media types. |
static <T> com.google.common.reflect.TypeToken<Stream<T>> |
streamOf(Class<T> type)
Creates specialized stream
type token for the given element class type. |
static <T> com.google.common.reflect.TypeToken<Stream<T>> |
streamOf(com.google.common.reflect.TypeToken<T> type)
Creates specialized stream
type token for the given element type token. |
public static final org.springframework.http.MediaType APPLICATION_JSON_SEQ
public static final org.springframework.http.MediaType APPLICATION_STREAM_JSON
public static final org.springframework.http.MediaType APPLICATION_X_JSON_STREAM
public static <T> com.google.common.reflect.TypeToken<Stream<T>> streamOf(Class<T> type)
type token for the given element class type. Used to
declare the expected stream response type token in Riptide route as follows:
on(...).call(streamOf(Result.class),...)
T - generic stream element typetype - element class type.public static <T> com.google.common.reflect.TypeToken<Stream<T>> streamOf(com.google.common.reflect.TypeToken<T> type)
type token for the given element type token. Used
to declare the expected stream response type token in Riptide org.zalando.riptide.Route route} as follows:
on(...).call(streamOf(resultTypeToken),...)
T - generic stream element typetype - element token type.public static <I,X extends Throwable> org.zalando.fauxpas.ThrowingConsumer<Stream<I>,X> forEach(org.zalando.fauxpas.ThrowingConsumer<I,X> consumer)
stream consumer for given element consumer. Commonly
used to wrap a single entity consumer function in a stream consumer function as follows:
on(...).call(streamOf(...), forEach(System.out::println))
I - generic stream element typeX - generic exception typeconsumer - element consumer function.public static <T> org.zalando.riptide.stream.StreamConverter<T> streamConverter()
T - generic stream element typepublic static <T> org.zalando.riptide.stream.StreamConverter<T> streamConverter(com.fasterxml.jackson.databind.ObjectMapper mapper)
object mapper.T - generic stream element typemapper - custom object mapper.public static <T> org.zalando.riptide.stream.StreamConverter<T> streamConverter(com.fasterxml.jackson.databind.ObjectMapper mapper, List<org.springframework.http.MediaType> supportedMediaTypes)
object mapper, and custom list of
supported media types.T - generic stream element typemapper - custom object mapper.supportedMediaTypes - custom list of media types.Copyright © 2015–2022 Zalando SE. All rights reserved.