Affects: 2.4.0


Implementing PATCH in WebFlux is giving me issues trying to return a 404 with the following code. The compiler complains that a Mono<ResponseEntity<Object>> is being returned instead of a Mono<ResponseEntity<Void>>

  public Mono<ResponseEntity<Void>> updatePost(
      UUID postId, Mono<UpdatePostRequest> updatePostRequest) {
    Mono<ninja.optimistic.api.blog.model.Post> post = REPOSITORY.findById(postId);
    return post.zipWith(updatePostRequest)
        .map(
            zip ->
                zip.getT1().toBuilder()
                    .title(
                        zip.getT2().getUpdateMask().contains(PostUpdateMask.TITLE)
                            ? zip.getT2().getTitle()
                            : zip.getT1().getTitle())
                    .summary(
                        zip.getT2().getUpdateMask().contains(PostUpdateMask.SUMMARY)
                            ? zip.getT2().getSummary()
                            : zip.getT1().getSummary())
                    .markdown(
                        zip.getT2().getUpdateMask().contains(PostUpdateMask.MARKDOWN)
                            ? zip.getT2().getMarkdown()
                            : zip.getT1().getMarkdown())
                    .imageUrl(
                        zip.getT2().getUpdateMask().contains(PostUpdateMask.IMAGE_URL)
                            ? zip.getT2().getImageUrl()
                            : zip.getT1().getImageUrl())
                    .build())
        .map(REPOSITORY::save)
        .thenReturn(noContent().build());
        //.defaultIfEmpty(notFound().build());
        // ^^ The offender
  }

Comment From: rstoyanchev

This is really a question about Java generics and more suited for StackOverflow rather than an actual issue to be filed here. That said the answer is relatively straightforward. The ResponseEntity doesn't specify Void in the generic type and so it is treated as Object. You can create variables with Void:

private static final ResponseEntity<Void> NO_CONTENT_RESPONSE = ResponseEntity.noContent().build();
private static final ResponseEntity<Void> NOT_FOUND_RESPONSE = ResponseEntity.notFound().build();

...

    .thenReturn(NO_CONTENT_RESPONSE)
    .defaultIfEmpty(NOT_FOUND_RESPONSE);