From 542de82c5fed3083b079673c791e91731e3c32e5 Mon Sep 17 00:00:00 2001 From: Rossen Stoyanchev Date: Thu, 4 Jan 2018 22:02:27 -0500 Subject: [PATCH] Document Jackson encoder/decoder behavior Issue: SPR-16260 --- src/docs/asciidoc/web/webflux.adoc | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/docs/asciidoc/web/webflux.adoc b/src/docs/asciidoc/web/webflux.adoc index 3543db2c3f..c1793a5e74 100644 --- a/src/docs/asciidoc/web/webflux.adoc +++ b/src/docs/asciidoc/web/webflux.adoc @@ -457,6 +457,33 @@ To configure or customize the readers and writers to use applications will typic +[[webflux-codecs-jackson-json]] +==== Jackson JSON + +The decoder relies on Jackson's non-blocking, byte array parser to parse a stream of byte +chunks into a `TokenBuffer` stream, which can then be turned into Objects with Jackson's +`ObjectMapper`. + +The encoder processes a `Publisher` as follows: + +* if the `Publisher` is a `Mono` (i.e. single value), the value is encoded to JSON. +* if media type is `application/stream+json`, each value produced by the +`Publisher` is encoded individually to JSON followed by a new line. +* otherwise all items from the `Publisher` are gathered in with `Flux#collectToList()` +and the resulting collection is encoded as a JSON array. + +As a special case to the above rules the `ServerSentEventHttpMessageWriter` feeds items +emitted from its input `Publisher` individually into the `Jackson2JsonEncoder` as a +`Mono`. + +Note that both the Jackson JSON encoder and decoder explicitly back out of rendering +elements of type `String`. Instead ``String``'s are treated as low level content, (i.e. +serialized JSON) and are rendered as-is by the `CharSequenceEncoder`. If you want a +`Flux` rendered as a JSON array, you'll have to use `Flux#collectToList()` and +provide a `Mono>` instead. + + + [[webflux-dispatcher-handler]] == DispatcherHandler