Skip to content

Commit 542de82

Browse files
committed
Document Jackson encoder/decoder behavior
Issue: SPR-16260
1 parent 7bf9b76 commit 542de82

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/docs/asciidoc/web/webflux.adoc

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,33 @@ To configure or customize the readers and writers to use applications will typic
457457

458458

459459

460+
[[webflux-codecs-jackson-json]]
461+
==== Jackson JSON
462+
463+
The decoder relies on Jackson's non-blocking, byte array parser to parse a stream of byte
464+
chunks into a `TokenBuffer` stream, which can then be turned into Objects with Jackson's
465+
`ObjectMapper`.
466+
467+
The encoder processes a `Publisher<?>` as follows:
468+
469+
* if the `Publisher` is a `Mono` (i.e. single value), the value is encoded to JSON.
470+
* if media type is `application/stream+json`, each value produced by the
471+
`Publisher` is encoded individually to JSON followed by a new line.
472+
* otherwise all items from the `Publisher` are gathered in with `Flux#collectToList()`
473+
and the resulting collection is encoded as a JSON array.
474+
475+
As a special case to the above rules the `ServerSentEventHttpMessageWriter` feeds items
476+
emitted from its input `Publisher` individually into the `Jackson2JsonEncoder` as a
477+
`Mono<?>`.
478+
479+
Note that both the Jackson JSON encoder and decoder explicitly back out of rendering
480+
elements of type `String`. Instead ``String``'s are treated as low level content, (i.e.
481+
serialized JSON) and are rendered as-is by the `CharSequenceEncoder`. If you want a
482+
`Flux<String>` rendered as a JSON array, you'll have to use `Flux#collectToList()` and
483+
provide a `Mono<List<String>>` instead.
484+
485+
486+
460487

461488
[[webflux-dispatcher-handler]]
462489
== DispatcherHandler

0 commit comments

Comments
 (0)