no-issue: Adding overloads to remove Class<T> param#1219
no-issue: Adding overloads to remove Class<T> param#1219ricardozanini merged 4 commits intoserverlessworkflow:mainfrom
Conversation
Signed-off-by: Ricardo Zanini <ricardozanini@gmail.com>
There was a problem hiding this comment.
Pull request overview
This PR updates the experimental fluent function DSL to infer lambda input types at runtime (via SerializedLambda) so callers can omit explicit Class<T> parameters, and expands the set of supported functional shapes (functions, predicates, consumers, and context-aware functions).
Changes:
- Introduce
Serializable*functional interfaces and update DSL entrypoints to accept them for runtime type inference. - Refactor
ReflectionUtilsto infer input types from any supported serializable lambda shape. - Add/adjust tests to exercise the new inferred-type overloads and DSL behavior.
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| experimental/types/src/main/java/io/serverlessworkflow/api/types/func/JavaFilterFunction.java | Makes JavaFilterFunction serializable to support runtime lambda introspection. |
| experimental/types/src/main/java/io/serverlessworkflow/api/types/func/JavaContextFunction.java | Makes JavaContextFunction serializable to support runtime lambda introspection. |
| experimental/lambda/src/test/java/io/serverless/workflow/impl/executors/func/WorkflowThenTest.java | Updates DSL usage to the new overload that infers input type (removes explicit Class). |
| experimental/lambda/src/test/java/io/serverless/workflow/impl/executors/func/FuncDSLReflectionsTest.java | Adds tests covering inferred-type overloads and reflective lambda handling. |
| experimental/fluent/func/src/main/java/io/serverlessworkflow/fluent/func/dsl/UniqueIdBiFunction.java | Makes the bi-function serializable for inference/introspection. |
| experimental/fluent/func/src/main/java/io/serverlessworkflow/fluent/func/dsl/SerializablePredicate.java | New serializable predicate type for switch/case inference. |
| experimental/fluent/func/src/main/java/io/serverlessworkflow/fluent/func/dsl/SerializableFunction.java | New serializable function type for task inference. |
| experimental/fluent/func/src/main/java/io/serverlessworkflow/fluent/func/dsl/SerializableConsumer.java | New serializable consumer type for consume(...) inference. |
| experimental/fluent/func/src/main/java/io/serverlessworkflow/fluent/func/dsl/ReflectionUtils.java | Refactors inference to use SerializedLambda and exposes overloads per supported functional type. |
| experimental/fluent/func/src/main/java/io/serverlessworkflow/fluent/func/dsl/InstanceIdBiFunction.java | Makes the injected-instance-id function serializable for inference/introspection. |
| experimental/fluent/func/src/main/java/io/serverlessworkflow/fluent/func/dsl/FuncEventFilterSpec.java | Updates JSON event data mapping to accept SerializableFunction and infer input class. |
| experimental/fluent/func/src/main/java/io/serverlessworkflow/fluent/func/dsl/FuncDSL.java | Adds overloads that remove Class<T> requirements using reflective inference. |
| experimental/fluent/func/src/main/java/io/serverlessworkflow/fluent/func/dsl/CommonFuncOps.java | Moves and adjusts internal ops to use serializable functional types for inference. |
| experimental/fluent/func/pom.xml | Formatting-only change. |
Comments suppressed due to low confidence (1)
experimental/fluent/func/src/main/java/io/serverlessworkflow/fluent/func/dsl/FuncDSL.java:287
- The Javadoc describes the expected
withContextsignature as(ctx, payload) -> result, butJavaContextFunctionis defined asapply(T payload, WorkflowContextData ctx). Please update the documentation to match the actual parameter order to avoid confusing DSL users.
* Build a call step for functions that need {@link WorkflowContextData} as the first parameter.
* The DSL wraps it as a {@link JavaContextFunction} and injects the runtime context.
*
* <p>Signature expected: {@code (ctx, payload) -> result}
*
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
...imental/fluent/func/src/main/java/io/serverlessworkflow/fluent/func/dsl/ReflectionUtils.java
Show resolved
Hide resolved
...imental/fluent/func/src/main/java/io/serverlessworkflow/fluent/func/dsl/ReflectionUtils.java
Show resolved
Hide resolved
experimental/fluent/func/src/main/java/io/serverlessworkflow/fluent/func/dsl/FuncDSL.java
Show resolved
Hide resolved
.../lambda/src/test/java/io/serverless/workflow/impl/executors/func/FuncDSLReflectionsTest.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Ricardo Zanini <ricardozanini@gmail.com>
Signed-off-by: Ricardo Zanini <ricardozanini@gmail.com>
| // Don't make this class public the ReflectionUtils must be accessed only by the DSL classes. | ||
|
|
There was a problem hiding this comment.
I think we can remove this comment
There was a problem hiding this comment.
Yeah, I'd like to reinforce that we never make this public. I guess we will have to do our due diligence when reviewing thou :)
Signed-off-by: Ricardo Zanini <ricardozanini@gmail.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 15 out of 15 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
experimental/fluent/func/src/main/java/io/serverlessworkflow/fluent/func/dsl/ReflectionUtils.java:26
- Unused import
java.util.function.Functioncauses a compilation failure here (it's only referenced in Javadoc). Remove the import or update the Javadoc to use a fully-qualified reference (and consider updating the class Javadoc since this utility now supports multiple serializable functional types, not justFunction).
import io.serverlessworkflow.api.types.func.JavaContextFunction;
import io.serverlessworkflow.api.types.func.JavaFilterFunction;
import java.lang.invoke.MethodType;
import java.lang.invoke.SerializedLambda;
import java.lang.reflect.Method;
import java.util.function.Function;
/**
* Specially used by {@link Function} parameters in the Java Function.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| * Extracts the input type using the resolved interface signature. * @param fn The serializable | ||
| * lambda | ||
| * |
There was a problem hiding this comment.
The Javadoc block is malformed: Extracts the input type... * @param fn has an inline * @param instead of starting a new line, which can break Javadoc rendering/checks. Reformat the comment so each @param tag starts on its own line.
| * Extracts the input type using the resolved interface signature. * @param fn The serializable | |
| * lambda | |
| * | |
| * Extracts the input type using the resolved interface signature. | |
| * | |
| * @param fn The serializable lambda |
Many thanks for submitting your Pull Request ❤️!
What this PR does / why we need it:
Class<T>requirementReflectingUtilsclass to accept any function, predicate, or consumer usageSerializableto our functions so we can infer types at runtimeSpecial notes for reviewers:
I haven't reviewed the changes throughout yet, I should do it tomorrow - improvements in an upcoming commit.
Additional information (if needed):