DefaultReturnValueHandlerManager class final
Central orchestrator that coordinates multiple ReturnValueHandler implementations within JetLeaf’s MVC layer.
This composite pattern allows JetLeaf to delegate controller method return value handling dynamically, ensuring that the appropriate specialized handler is chosen for each scenario (e.g., view rendering, JSON serialization, redirects, etc.).
Overview
The DefaultReturnValueHandler maintains a registry of
available ReturnValueHandlers. Each handler declares which
return values it can process via canHandle.
When a controller method returns a value, the composite searches the ordered
list of handlers and delegates execution to the first compatible one.
Handlers are automatically discovered and registered from the active
ApplicationContext at startup, ensuring modular extensibility.
Responsibilities
- Maintain an ordered list of return value handlers
- Automatically discover and initialize handlers via
ApplicationContext - Delegate return value processing to the first matching handler
- Exclude advice-related controllers (
@ControllerAdvice,@RestControllerAdvice) - Support concurrent-safe registration through internal synchronization
Example
final composite = DefaultReturnValueHandler();
composite.addHandlers([
ViewRenderReturnValueHandler(),
JsonReturnValueHandler(converters),
StringReturnValueHandler(),
]);
final handler = composite.findHandler(method, returnValue, request);
if (handler != null) {
await handler.handleReturnValue(returnValue, method, request, response, hm);
}
Handler Resolution Order
Handlers are ordered using AnnotationAwareOrderComparator,
allowing priority control through the @Order annotation.
Lifecycle Integration
As an InitializingPod, this class automatically loads all available
handler pods from the application context during startup.
Handlers discovered at runtime can also be added manually via addHandler.
Related Components
- ReturnValueHandler — base strategy interface
- JsonReturnValueHandler, StringReturnValueHandler, RedirectReturnValueHandler, VoidReturnValueHandler — concrete strategies
ApplicationContext— provides handler discovery and lifecycle management
- Implemented types
- Annotations
-
- @Author.new("Evaristus Adimonyemma")
Constructors
- DefaultReturnValueHandlerManager(ContentNegotiationResolver _negotiationResolver)
- Central orchestrator that coordinates multiple ReturnValueHandler implementations within JetLeaf’s MVC layer.
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
addHandler(
ReturnValueHandler handler) → void - Registers a new handler, replacing any existing instance of the same type.
-
addHandlers(
Iterable< ReturnValueHandler> handlers) → void - Registers multiple handlers at once, clearing cached order.
-
canHandle(
Method? method, Object? returnValue, ServerHttpRequest request) → bool -
Determines whether this handler can handle the given return value.
override
-
equalizedProperties(
) → List< Object?> -
Mixin-style contract for value-based equality,
hashCode, andtoString. -
findHandler(
Method? method, Object? returnValue, ServerHttpRequest request) → ReturnValueHandler? -
Finds a ReturnValueHandler capable of processing the given
returnValue.override -
getHandlers(
) → List< ReturnValueHandler> -
Returns the ordered list of all registered ReturnValueHandlers
managed by this instance.
override
-
getPackageName(
) → String - Represents an abstraction for identifying the package that an object, resource, or service belongs to.
-
getSupportedMediaTypes(
) → List< MediaType> -
Returns the list of media types this handler supports by default.
override
-
handleReturnValue(
Object? returnValue, Method? method, ServerHttpRequest request, ServerHttpResponse response, HandlerMethod? hm) → Future< void> -
Processes the return value and writes the appropriate response.
override
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
onReady(
) → Future< void> - Interface to be implemented by pods that require initialization logic after their properties have been set by the container.
-
setApplicationContext(
ApplicationContext applicationContext) → void -
Sets the
ApplicationContextthat this component runs in. -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited