When upgrading a Springboot application using org.springframework.boot:spring-boot-starter-webflux:2.1.10.RELEASE to org.springframework.boot:spring-boot-starter-webflux:2.3.3.RELEASE I have noticed a change in behavior of my code.

Optional<CustomerMapping> customerMappingOptional = webClientCustomerAdapter
                .get()
                .uri("/api/v1/customers/mapping/{uuid}", uuid)
                .retrieve()
                .onStatus(HttpStatus.NOT_FOUND::equals, response -> Mono.empty())
                .bodyToMono(CustomerMapping.class)
                .blockOptional();

Using webflux 2.1.10 when the rest call returns a “not found”, the customerMappingOptional becomes an empty Optional. Using webflux 2.3.3 when the rest call returns a “not found”, the customerMappingOptional becomes an Optional with a value: a Customer object where all fields are null values.

I would like to hear the opinion of the Sprint developers on this matter.

Comment From: rstoyanchev

This behavior changed in 5.2 following this change a9b3d95a14c316387f2b77328d6864b8e0a36721. Note that the previous behavior could lead to further issues if the response had content. In order to achieve the same, take a look at the Javadoc of onStatus which mentions this very scenario.