mirror of
https://github.com/spring-projects/spring-framework.git
synced 2026-10-05 14:40:04 +00:00
Add Gson codecs for WebFlux
This commit adds new `GsonEncoder` and `GsonDecoder` for serializing and deserializing JSON in a reactive fashion. Because `Gson` itslef does not support decoding JSON in a non-blocking way, the `GsonDecoder` does not support decoding to `Flux<*>` types. Closes gh-27131
This commit is contained in:
@@ -545,6 +545,20 @@ The `ProtobufJsonDecoder` and `ProtobufJsonEncoder` variants support reading and
|
||||
They require the "com.google.protobuf:protobuf-java-util" dependency. Note, the JSON variants do not support reading stream of messages,
|
||||
see the {spring-framework-api}/http/codec/protobuf/ProtobufJsonDecoder.html[javadoc of `ProtobufJsonDecoder`] for more details.
|
||||
|
||||
[[webflux-codecs-gson]]
|
||||
=== Google Gson
|
||||
|
||||
Applications can use the `GsonEncoder` and `GsonDecoder` to serialize and deserialize JSON documents thanks to the https://google.github.io/gson/[Google Gson] library .
|
||||
This codec supports both JSON media types and the NDJSON format for streaming.
|
||||
|
||||
[NOTE]
|
||||
====
|
||||
`Gson` does not support non-blocking parsing, so the `GsonDecoder` does not support deserializing
|
||||
to `Flux<*>` types. For example, if this decoder is used for deserializing a JSON stream or even a list of elements
|
||||
as a `Flux<*>`, an `UnsupportedOperationException` will be thrown at runtime.
|
||||
Applications should instead focus on deserializing bounded collections and use `Mono<List<*>>` as target types.
|
||||
====
|
||||
|
||||
[[webflux-codecs-limits]]
|
||||
=== Limits
|
||||
|
||||
|
||||
Reference in New Issue
Block a user