Class OptionHandlerMethodReturnValueHandler

java.lang.Object
dmx.fun.spring.boot.web.OptionHandlerMethodReturnValueHandler
All Implemented Interfaces:
org.springframework.web.method.support.HandlerMethodReturnValueHandler

@NullMarked public final class OptionHandlerMethodReturnValueHandler extends Object implements org.springframework.web.method.support.HandlerMethodReturnValueHandler
Spring MVC HandlerMethodReturnValueHandler that converts Option return values into HTTP responses automatically:
  • Option.some(Object) → HTTP 200 with the unwrapped value serialized by the delegate HandlerMethodReturnValueHandler (typically RequestResponseBodyMethodProcessor).
  • Option.none() → HTTP 404 with an empty body.

This handler is registered automatically by DmxFunWebMvcAutoConfiguration before the built-in body processor, so controller methods in @RestController classes can declare Option<T> as their return type and receive the correct HTTP semantics without any extra boilerplate.

Example:

@GetMapping("/{id}")
public Option<Item> findById(@PathVariable("id") Long id) {
    return service.findById(id);   // some → 200, none → 404
}
  • Constructor Summary

    Constructors
    Constructor
    Description
    OptionHandlerMethodReturnValueHandler(org.springframework.web.method.support.HandlerMethodReturnValueHandler delegate)
    Creates a handler that unwraps Option return values and delegates serialization of the unwrapped value to the given handler.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    handleReturnValue(@Nullable Object returnValue, org.springframework.core.MethodParameter returnType, org.springframework.web.method.support.ModelAndViewContainer mavContainer, org.springframework.web.context.request.NativeWebRequest webRequest)
     
    boolean
    supportsReturnType(org.springframework.core.MethodParameter returnType)
     

    Methods inherited from class Object

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

    • OptionHandlerMethodReturnValueHandler

      public OptionHandlerMethodReturnValueHandler(org.springframework.web.method.support.HandlerMethodReturnValueHandler delegate)
      Creates a handler that unwraps Option return values and delegates serialization of the unwrapped value to the given handler.
      Parameters:
      delegate - the handler that processes the unwrapped value — typically a RequestResponseBodyMethodProcessor that writes the body using the configured HttpMessageConverters
  • Method Details

    • supportsReturnType

      public boolean supportsReturnType(org.springframework.core.MethodParameter returnType)
      Specified by:
      supportsReturnType in interface org.springframework.web.method.support.HandlerMethodReturnValueHandler
    • handleReturnValue

      public void handleReturnValue(@Nullable Object returnValue, org.springframework.core.MethodParameter returnType, org.springframework.web.method.support.ModelAndViewContainer mavContainer, org.springframework.web.context.request.NativeWebRequest webRequest) throws Exception
      Specified by:
      handleReturnValue in interface org.springframework.web.method.support.HandlerMethodReturnValueHandler
      Throws:
      Exception