Add NDJSON and deprecate application/stream+json
Closes gh-21283
This commit is contained in:
@@ -378,7 +378,7 @@ You can also use https://github.com/jayway/JsonPath[JSONPath] expressions, as fo
|
||||
[[webtestclient-stream]]
|
||||
=== Streaming Responses
|
||||
|
||||
To test infinite streams (for example, `"text/event-stream"` or `"application/stream+json"`),
|
||||
To test infinite streams (for example, `"text/event-stream"` or `"application/x-ndjson"`),
|
||||
you need to exit the chained API (by using `returnResult`), immediately after the response status
|
||||
and header assertions, as the following example shows:
|
||||
|
||||
|
||||
@@ -755,9 +755,9 @@ into ``TokenBuffer``'s each representing a JSON object.
|
||||
* When decoding to a single-value publisher (e.g. `Mono`), there is one `TokenBuffer`.
|
||||
* When decoding to a multi-value publisher (e.g. `Flux`), each `TokenBuffer` is passed to
|
||||
the `ObjectMapper` as soon as enough bytes are received for a fully formed object. The
|
||||
input content can be a JSON array, or
|
||||
https://en.wikipedia.org/wiki/JSON_streaming[line-delimited JSON] if the content-type is
|
||||
`application/stream+json`.
|
||||
input content can be a JSON array, or any
|
||||
https://en.wikipedia.org/wiki/JSON_streaming[line-delimited JSON] format such as NDJSON,
|
||||
JSON Lines, or JSON Text Sequences.
|
||||
|
||||
The `Jackson2Encoder` works as follows:
|
||||
|
||||
@@ -766,9 +766,10 @@ The `Jackson2Encoder` works as follows:
|
||||
* For a multi-value publisher with `application/json`, by default collect the values with
|
||||
`Flux#collectToList()` and then serialize the resulting collection.
|
||||
* For a multi-value publisher with a streaming media type such as
|
||||
`application/stream+json` or `application/stream+x-jackson-smile`, encode, write, and
|
||||
`application/x-ndjson` or `application/stream+x-jackson-smile`, encode, write, and
|
||||
flush each value individually using a
|
||||
https://en.wikipedia.org/wiki/JSON_streaming[line-delimited JSON] format.
|
||||
https://en.wikipedia.org/wiki/JSON_streaming[line-delimited JSON] format. Other
|
||||
streaming media types may be registered with the encoder.
|
||||
* For SSE the `Jackson2Encoder` is invoked per event and the output is flushed to ensure
|
||||
delivery without delay.
|
||||
|
||||
@@ -852,7 +853,7 @@ To configure all three in WebFlux, you'll need to supply a pre-configured instan
|
||||
[.small]#<<web.adoc#mvc-ann-async-http-streaming, Web MVC>>#
|
||||
|
||||
When streaming to the HTTP response (for example, `text/event-stream`,
|
||||
`application/stream+json`), it is important to send data periodically, in order to
|
||||
`application/x-ndjson`), it is important to send data periodically, in order to
|
||||
reliably detect a disconnected client sooner rather than later. Such a send could be a
|
||||
comment-only, empty SSE event or any other "no-op" data that would effectively serve as
|
||||
a heartbeat.
|
||||
|
||||
@@ -4581,7 +4581,7 @@ Reactive return values are handled as follows:
|
||||
|
||||
* A single-value promise is adapted to, similar to using `DeferredResult`. Examples
|
||||
include `Mono` (Reactor) or `Single` (RxJava).
|
||||
* A multi-value stream with a streaming media type (such as `application/stream+json`
|
||||
* A multi-value stream with a streaming media type (such as `application/x-ndjson`
|
||||
or `text/event-stream`) is adapted to, similar to using `ResponseBodyEmitter` or
|
||||
`SseEmitter`. Examples include `Flux` (Reactor) or `Observable` (RxJava).
|
||||
Applications can also return `Flux<ServerSentEvent>` or `Observable<ServerSentEvent>`.
|
||||
|
||||
Reference in New Issue
Block a user