Skip to content

wemu/webclient-demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

The quirks of Spring WebClient and List<String>

As of Spring Core 5.0 the RestTemplate is in maintenance mode and it is suggested to use the new WebClient.

The new WebClient has a nice API and due to its reactive support (sync, async, stream) feels quite future-proof.

It's all nice and shiny. Until you try to read a List<String> from a rest endpoint.

If you are not very careful the client will not throw an exception, but it will also not return the list of string, rather you will end up with a list containing only one entry or more (depending on the newlines in the rest endpoint response).

There are some related questions on Stackoverflow and reported issues in the issue tracker:

As you read through the issue tracker there is good news. It will work! But not the way you think it will. The behaviour of WebClient to treat List<String> differently as everything else is intentional. Read about this in the Spring Docs Jackson JSON and about line-delimited JSON.

This repository shows variations of using WebClient to be able to read a List<String> from a rest endpoint without sacrificing type support or too ugly code.

NOTE: using .block() is only allowed when you know what you are doing.

About

Repository to show how to handle List<String> with the new Spring WebClient

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages