Class WebfluxEntity

java.lang.Object
dmx.fun.spring.webflux.WebfluxEntity

@NullMarked public final class WebfluxEntity extends Object
Maps dmx-fun outcomes to a ResponseEntity for Spring WebFlux annotation controllers (@RestController), the counterpart of WebfluxFun (which targets ServerResponse for functional endpoints).

A controller method returns the adapter's Mono<ResponseEntity<…>> directly, so it maps a domain outcome instead of re-implementing status/body conventions:

@GetMapping("/users/{id}")
Mono<ResponseEntity<User>> user(@PathVariable String id) {
    return WebfluxEntity.fromOption(userService.find(id));   // Some -> 200, None/empty -> 404
}

@GetMapping("/orders/{id}")
Mono<ResponseEntity<?>> order(@PathVariable String id) {
    return WebfluxEntity.fromResult(orderService.findById(id),   // Mono<Result<Order, ApiError>>
        error -> ResponseEntity.status(error.status()).body(error.detail()));
}

HTTP conventions mirror WebfluxFun: Ok/Some/Success/Valid200 with the value as the body; None, an empty source Mono404; Invalid400 with the accumulated errors; Err/Failure → your mapper.

  • Method Summary

    Modifier and Type
    Method
    Description
    static <V> reactor.core.publisher.Mono<org.springframework.http.ResponseEntity<V>>
    fromOption(reactor.core.publisher.Mono<Option<V>> source)
    Maps an Option: Some(v)200 with v; None or an empty source Mono404.
    static <V,E> reactor.core.publisher.Mono<org.springframework.http.ResponseEntity<?>>
    fromResult(reactor.core.publisher.Mono<Result<V,E>> source, Function<? super E, org.springframework.http.ResponseEntity<?>> onError)
    Maps a Result: Ok(v)200 with v; Err(e)onError; an empty source Mono404.
    static <V> reactor.core.publisher.Mono<org.springframework.http.ResponseEntity<?>>
    fromTry(reactor.core.publisher.Mono<Try<V>> source, Function<? super Throwable, org.springframework.http.ResponseEntity<?>> onFailure)
    Maps a Try: Success(v)200 with v; Failure(t)onFailure; an empty source Mono404.
    static <E,V> reactor.core.publisher.Mono<org.springframework.http.ResponseEntity<?>>
    fromValidated(reactor.core.publisher.Mono<Validated<NonEmptyList<E>, V>> source)
    Maps a Validated: Valid(v)200 with v; Invalid(errors)400 carrying every error (as a list); an empty source Mono404.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • fromOption

      public static <V> reactor.core.publisher.Mono<org.springframework.http.ResponseEntity<V>> fromOption(reactor.core.publisher.Mono<Option<V>> source)
      Maps an Option: Some(v)200 with v; None or an empty source Mono404.
      Type Parameters:
      V - the body type
      Parameters:
      source - the upstream option
      Returns:
      a Mono emitting the response entity
    • fromResult

      public static <V,E> reactor.core.publisher.Mono<org.springframework.http.ResponseEntity<?>> fromResult(reactor.core.publisher.Mono<Result<V,E>> source, Function<? super E, org.springframework.http.ResponseEntity<?>> onError)
      Maps a Result: Ok(v)200 with v; Err(e)onError; an empty source Mono404.
      Type Parameters:
      V - the success body type
      E - the error type
      Parameters:
      source - the upstream result
      onError - maps the error to a response entity (status and body of your choosing)
      Returns:
      a Mono emitting the response entity
    • fromTry

      public static <V> reactor.core.publisher.Mono<org.springframework.http.ResponseEntity<?>> fromTry(reactor.core.publisher.Mono<Try<V>> source, Function<? super Throwable, org.springframework.http.ResponseEntity<?>> onFailure)
      Maps a Try: Success(v)200 with v; Failure(t)onFailure; an empty source Mono404.
      Type Parameters:
      V - the success body type
      Parameters:
      source - the upstream try
      onFailure - maps the throwable to a response entity
      Returns:
      a Mono emitting the response entity
    • fromValidated

      public static <E,V> reactor.core.publisher.Mono<org.springframework.http.ResponseEntity<?>> fromValidated(reactor.core.publisher.Mono<Validated<NonEmptyList<E>, V>> source)
      Maps a Validated: Valid(v)200 with v; Invalid(errors)400 carrying every error (as a list); an empty source Mono404.
      Type Parameters:
      E - the error type
      V - the valid body type
      Parameters:
      source - the upstream validated outcome accumulating errors in a NonEmptyList
      Returns:
      a Mono emitting the response entity