2
votes

I have a simple program with two parts: a Spring 5 server with one endpoint that returns a Mono<Double>, and a client program that reads the value and prints it.

When I browse to http://localhost:8080/rand a double value is returned. However, when I use the client the retrieved value is always null (response status is 200).

What am I missing?

File Main.java

@SpringBootApplication
@EnableWebFlux
public class Main {
    public static void main(String... args) {
        SpringApplication.run(Main.class);
    }
}

File MyController.java

@RestController
public class MyController {
    @GetMapping("/rand")
    public Mono<Double> GetDouble() {
        return Mono.just(ThreadLocalRandom.current().nextDouble());
    }
}

File MyClient.java

public class MyClient {
    public static void main(String... args) {
        WebClient client = WebClient.create("http://localhost:8080");

        Double value = client.get()
                .uri("/rand")
                .accept(MediaType.APPLICATION_JSON)
                .retrieve()
                .bodyToMono(Double.class)
                .block();
        System.out.println("value = " + value);
    }
}
1
created another question with some findings regarding the same. stackoverflow.com/questions/47420900/…pvpkiran
both questions are about the same issue, essentially duplicating each other...Brian Clozel

1 Answers

2
votes

This is a know issue with Spring Framework 5.0.1, see SPR-16166 for more information.