Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to async parse/write json in webflux? ObjectMapper methods are blocking

I saw that jackson supports non-blocking since 2.9, but how to use it with webflux? Is there a demo?

like image 611
Bill Billy Avatar asked Jul 01 '26 13:07

Bill Billy


1 Answers

Here is how you can use WebClient to make a GET request to Github’s List Repositories API

public Flux<GithubRepo> listGithubRepositories(String username, String token) {
     return webClient.get()
            .uri("/user/repos")
            .header("Authorization", "Basic " + Base64Utils
                    .encodeToString((username + ":" + token).getBytes(UTF_8)))
            .retrieve()
            .bodyToFlux(GithubRepo.class);
}

Assuming we have a class named GithubRepo that confirms to the Github’s API response, the above function will return a Flux of GithubRepo objects.

like image 129
Rajesh Avatar answered Jul 04 '26 04:07

Rajesh