Skip to content

no-issue: Adding overloads to remove Class<T> param#1219

Merged
ricardozanini merged 4 commits intoserverlessworkflow:mainfrom
ricardozanini:add-generics-dsl
Mar 10, 2026
Merged

no-issue: Adding overloads to remove Class<T> param#1219
ricardozanini merged 4 commits intoserverlessworkflow:mainfrom
ricardozanini:add-generics-dsl

Conversation

@ricardozanini
Copy link
Member

Many thanks for submitting your Pull Request ❤️!

What this PR does / why we need it:

  • Overload some DSL methods to remove the Class<T> requirement
  • Refactor the ReflectingUtils class to accept any function, predicate, or consumer usage
  • Add Serializable to our functions so we can infer types at runtime

Special 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):

Signed-off-by: Ricardo Zanini <ricardozanini@gmail.com>
Copilot AI review requested due to automatic review settings March 9, 2026 23:13
@ricardozanini ricardozanini requested a review from fjtirado as a code owner March 9, 2026 23:13
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ReflectionUtils to 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 withContext signature as (ctx, payload) -> result, but JavaContextFunction is defined as apply(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.

Signed-off-by: Ricardo Zanini <ricardozanini@gmail.com>
Signed-off-by: Ricardo Zanini <ricardozanini@gmail.com>
Comment on lines +25 to +26
// Don't make this class public the ReflectionUtils must be accessed only by the DSL classes.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can remove this comment

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
Copilot AI review requested due to automatic review settings March 10, 2026 16:18
@ricardozanini ricardozanini merged commit d0f6d71 into serverlessworkflow:main Mar 10, 2026
5 checks passed
@ricardozanini ricardozanini deleted the add-generics-dsl branch March 10, 2026 16:20
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.Function causes 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 just Function).
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.

Comment on lines +70 to +72
* Extracts the input type using the resolved interface signature. * @param fn The serializable
* lambda
*
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
* 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

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants