Class ParamBeanMapper

java.lang.Object
com.tnsai.actions.ParamBeanMapper

public final class ParamBeanMapper extends Object
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 / isX accessors — accessor name (with the prefix stripped + first char lower-cased) becomes the map key. Methods inherited from Object are 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-args executeAction(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 Details

    • toMap

      public static Map<String,Object> toMap(Object bean)
      Convert the supplied input bean to a parameter map.
      Parameters:
      bean - a Map, a record, a POJO, or null
      Returns:
      a Map<String, Object> ready for executeAction(name, map)
      Throws:
      IllegalStateException - if reflective access to a record component or accessor fails
    • describe

      public static String describe(Object bean)
      Diagnostic: describe how the supplied bean would be mapped, without actually invoking accessors. Useful for error messages and tests.