Package com.tnsai.actions
Class ParamBeanMapper
java.lang.Object
com.tnsai.actions.ParamBeanMapper
Reflectively maps a typed input bean (Java
record or POJO with
accessors / public fields) to a Map<String, Object> suitable for
the framework's existing executeAction(String, Map) dispatch path.
Lets consumers replace stringly-typed call sites:
agent.executeAction("summarise", Map.of(
"path", "/data/sales.csv",
"question", "Top region?"
));
… with a typed input record:
public record SummariseInput(String path, String question) {}
agent.executeAction("summarise", new SummariseInput(
"/data/sales.csv", "Top region?"
));
The Object-overload of Agent.executeAction(String, Object)
delegates to this mapper before forwarding the resulting map to the
untyped dispatch path. IDE auto-completion, refactor safety, and
compile-time typo checks come for free.
Bean shapes accepted
Map<String, Object>— returned as-is.- Java
record— components mapped by name to map keys. - POJO with public
getX/isXaccessors — accessor name (with the prefix stripped + first char lower-cased) becomes the map key. Methods inherited fromObjectare skipped. - POJO with no accessors — public non-static fields are read directly (Lombok-free shape; useful for ad-hoc input holders).
null— returns an empty map, mirroring the no-argsexecuteAction(actionName)call.
Null component / accessor values are preserved as null entries
so the framework's parameter binding can decide how to treat them.
- Since:
- 0.8.0
-
Method Summary
-
Method Details
-
toMap
Convert the supplied input bean to a parameter map.- Parameters:
bean- aMap, arecord, a POJO, ornull- Returns:
- a
Map<String, Object>ready forexecuteAction(name, map) - Throws:
IllegalStateException- if reflective access to a record component or accessor fails
-
describe
Diagnostic: describe how the supplied bean would be mapped, without actually invoking accessors. Useful for error messages and tests.
-