Class JsonLines
java.lang.Object
com.linecorp.armeria.server.streaming.JsonLines
A utility class which helps to create a JavaScript Object
Notation (JSON) Lines text from a content
Publisher
or Stream
.
A user simply creates a streaming HttpResponse
which emits JSON Lines text, e.g.
ObjectMapper mapper = new ObjectMapper().enable(SerializationFeature.WRITE_ENUMS_USING_INDEX);
Server server =
Server.builder()
// Emit JSON Lines Text with a default ObjectMapper.
.service("/seq1",
(ctx, req) -> JsonLines.fromPublisher(Flux.just("foo", "bar")))
// Emit JSON Lines Text with the ObjectMapper
// configured to use SerializationFeature.WRITE_ENUMS_USING_INDEX.
.service("/seq2",
(ctx, req) -> JsonLines.fromPublisher(Flux.just("foo", "bar"), mapper))
.build();
-
Method Summary
Modifier and TypeMethodDescriptionstatic HttpResponse
fromObject
(@Nullable Object content) Returns a newly created JSON Lines response from the specifiedcontent
.static HttpResponse
fromObject
(ResponseHeaders headers, @Nullable Object content) Returns a newly created JSON Lines response from the specifiedcontent
.static HttpResponse
fromObject
(ResponseHeaders headers, @Nullable Object content, ObjectMapper mapper) Returns a newly created JSON Lines response from the specifiedcontent
.static HttpResponse
fromObject
(ResponseHeaders headers, @Nullable Object content, HttpHeaders trailers, ObjectMapper mapper) Returns a newly created JSON Lines response from the specifiedcontent
.static HttpResponse
fromPublisher
(ResponseHeaders headers, org.reactivestreams.Publisher<?> contentPublisher) Returns a newly created JSON Lines response from the specifiedPublisher
.static HttpResponse
fromPublisher
(ResponseHeaders headers, org.reactivestreams.Publisher<?> contentPublisher, ObjectMapper mapper) Returns a newly created JSON Lines response from the specifiedPublisher
.static HttpResponse
fromPublisher
(ResponseHeaders headers, org.reactivestreams.Publisher<?> contentPublisher, HttpHeaders trailers, ObjectMapper mapper) Returns a newly created JSON Lines response from the specifiedPublisher
.static HttpResponse
fromPublisher
(org.reactivestreams.Publisher<?> contentPublisher) Returns a newly created JSON Lines response from the specifiedPublisher
.static HttpResponse
fromPublisher
(org.reactivestreams.Publisher<?> contentPublisher, ObjectMapper mapper) Returns a newly created JSON Lines response from specifiedPublisher
.static HttpResponse
fromStream
(ResponseHeaders headers, Stream<?> contentStream, HttpHeaders trailers, Executor executor, ObjectMapper mapper) Returns a newly created JSON Lines response from the specifiedStream
.static HttpResponse
fromStream
(ResponseHeaders headers, Stream<?> contentStream, Executor executor) Returns a newly created JSON Lines response from the specifiedStream
.static HttpResponse
fromStream
(ResponseHeaders headers, Stream<?> contentStream, Executor executor, ObjectMapper mapper) Returns a newly created JSON Lines response from the specifiedStream
.static HttpResponse
fromStream
(Stream<?> contentStream, Executor executor) Returns a newly created JSON Lines response from the specifiedStream
.static HttpResponse
fromStream
(Stream<?> contentStream, Executor executor, ObjectMapper mapper) Returns a newly created JSON Lines response from the specifiedStream
.
-
Method Details
-
fromPublisher
Returns a newly created JSON Lines response from the specifiedPublisher
.- Parameters:
contentPublisher
- thePublisher
which publishes the objects supposed to send as contents
-
fromPublisher
public static HttpResponse fromPublisher(org.reactivestreams.Publisher<?> contentPublisher, ObjectMapper mapper) Returns a newly created JSON Lines response from specifiedPublisher
.- Parameters:
contentPublisher
- thePublisher
which publishes the objects supposed to send as contentsmapper
- the mapper which converts the content object into JSON Lines
-
fromPublisher
public static HttpResponse fromPublisher(ResponseHeaders headers, org.reactivestreams.Publisher<?> contentPublisher) Returns a newly created JSON Lines response from the specifiedPublisher
.- Parameters:
headers
- the HTTP headers supposed to sendcontentPublisher
- thePublisher
which publishes the objects supposed to send as contents
-
fromPublisher
public static HttpResponse fromPublisher(ResponseHeaders headers, org.reactivestreams.Publisher<?> contentPublisher, ObjectMapper mapper) Returns a newly created JSON Lines response from the specifiedPublisher
.- Parameters:
headers
- the HTTP headers supposed to sendcontentPublisher
- thePublisher
which publishes the objects supposed to send as contentsmapper
- the mapper which converts the content object into JSON Lines
-
fromPublisher
public static HttpResponse fromPublisher(ResponseHeaders headers, org.reactivestreams.Publisher<?> contentPublisher, HttpHeaders trailers, ObjectMapper mapper) Returns a newly created JSON Lines response from the specifiedPublisher
.- Parameters:
headers
- the HTTP headers supposed to sendcontentPublisher
- thePublisher
which publishes the objects supposed to send as contentstrailers
- the HTTP trailersmapper
- the mapper which converts the content object into JSON Lines
-
fromStream
Returns a newly created JSON Lines response from the specifiedStream
.- Parameters:
contentStream
- theStream
which publishes the objects supposed to send as contentsexecutor
- the executor which iterates the stream
-
fromStream
public static HttpResponse fromStream(Stream<?> contentStream, Executor executor, ObjectMapper mapper) Returns a newly created JSON Lines response from the specifiedStream
.- Parameters:
contentStream
- theStream
which publishes the objects supposed to send as contentsexecutor
- the executor which iterates the stream
-
fromStream
public static HttpResponse fromStream(ResponseHeaders headers, Stream<?> contentStream, Executor executor) Returns a newly created JSON Lines response from the specifiedStream
.- Parameters:
headers
- the HTTP headers supposed to sendcontentStream
- theStream
which publishes the objects supposed to send as contentsexecutor
- the executor which iterates the stream
-
fromStream
public static HttpResponse fromStream(ResponseHeaders headers, Stream<?> contentStream, Executor executor, ObjectMapper mapper) Returns a newly created JSON Lines response from the specifiedStream
.- Parameters:
headers
- the HTTP headers supposed to sendcontentStream
- theStream
which publishes the objects supposed to send as contentsexecutor
- the executor which iterates the streammapper
- the mapper which converts the content object into JSON Lines
-
fromStream
public static HttpResponse fromStream(ResponseHeaders headers, Stream<?> contentStream, HttpHeaders trailers, Executor executor, ObjectMapper mapper) Returns a newly created JSON Lines response from the specifiedStream
.- Parameters:
headers
- the HTTP headers supposed to sendcontentStream
- theStream
which publishes the objects supposed to send as contentstrailers
- the HTTP trailersexecutor
- the executor which iterates the streammapper
- the mapper which converts the content object into JSON Lines
-
fromObject
Returns a newly created JSON Lines response from the specifiedcontent
.- Parameters:
content
- the object supposed to send as contents
-
fromObject
Returns a newly created JSON Lines response from the specifiedcontent
.- Parameters:
headers
- the HTTP headers supposed to sendcontent
- the object supposed to send as contents
-
fromObject
public static HttpResponse fromObject(ResponseHeaders headers, @Nullable @Nullable Object content, ObjectMapper mapper) Returns a newly created JSON Lines response from the specifiedcontent
.- Parameters:
headers
- the HTTP headers supposed to sendcontent
- the object supposed to send as contentsmapper
- the mapper which converts the content object into JSON Lines
-
fromObject
public static HttpResponse fromObject(ResponseHeaders headers, @Nullable @Nullable Object content, HttpHeaders trailers, ObjectMapper mapper) Returns a newly created JSON Lines response from the specifiedcontent
.- Parameters:
headers
- the HTTP headers supposed to sendcontent
- the object supposed to send as contentstrailers
- the HTTP trailersmapper
- the mapper which converts the content object into JSON Lines
-