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 delegateHandlerMethodReturnValueHandler(typicallyRequestResponseBodyMethodProcessor).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
ConstructorsConstructorDescriptionOptionHandlerMethodReturnValueHandler(org.springframework.web.method.support.HandlerMethodReturnValueHandler delegate) Creates a handler that unwrapsOptionreturn values and delegates serialization of the unwrapped value to the given handler. -
Method Summary
Modifier and TypeMethodDescriptionvoidhandleReturnValue(@Nullable Object returnValue, org.springframework.core.MethodParameter returnType, org.springframework.web.method.support.ModelAndViewContainer mavContainer, org.springframework.web.context.request.NativeWebRequest webRequest) booleansupportsReturnType(org.springframework.core.MethodParameter returnType)
-
Constructor Details
-
OptionHandlerMethodReturnValueHandler
public OptionHandlerMethodReturnValueHandler(org.springframework.web.method.support.HandlerMethodReturnValueHandler delegate) Creates a handler that unwrapsOptionreturn values and delegates serialization of the unwrapped value to the given handler.- Parameters:
delegate- the handler that processes the unwrapped value — typically aRequestResponseBodyMethodProcessorthat writes the body using the configuredHttpMessageConverters
-
-
Method Details
-
supportsReturnType
public boolean supportsReturnType(org.springframework.core.MethodParameter returnType) - Specified by:
supportsReturnTypein interfaceorg.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:
handleReturnValuein interfaceorg.springframework.web.method.support.HandlerMethodReturnValueHandler- Throws:
Exception
-