Skip to content

Fix #1275 - Improve CloudEvent and CloudEventData handling#1282

Merged
fjtirado merged 7 commits intoserverlessworkflow:mainfrom
ricardozanini:issue-1275
Apr 1, 2026
Merged

Fix #1275 - Improve CloudEvent and CloudEventData handling#1282
fjtirado merged 7 commits intoserverlessworkflow:mainfrom
ricardozanini:issue-1275

Conversation

@ricardozanini
Copy link
Copy Markdown
Member

Fix #1275

WIP

Signed-off-by: Ricardo Zanini <ricardozanini@gmail.com>
Signed-off-by: Ricardo Zanini <ricardozanini@gmail.com>
@ricardozanini ricardozanini marked this pull request as ready for review March 30, 2026 18:48
@ricardozanini ricardozanini requested a review from fjtirado as a code owner March 30, 2026 18:48
Copilot AI review requested due to automatic review settings March 30, 2026 18:48
@ricardozanini ricardozanini changed the title [WIP] - Fix #1275 - Improve CloudEvent and CloudEventData handling Fix #1275 - Improve CloudEvent and CloudEventData handling Mar 30, 2026
Copy link
Copy Markdown
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

Addresses #1275 by removing the static ObjectMapper caching trap, adding native CloudEvents serialization/deserialization support, and improving collection/type adaptation in the model layer to support event filtering use cases.

Changes:

  • Make JsonUtils fetch the ObjectMapper dynamically and add explicit CloudEvent / CloudEventData conversions via CloudEvents SDK utilities.
  • Add a default fallback ObjectMapper that registers the CloudEvents Jackson module, plus unit tests validating the new behavior.
  • Expand WorkflowModelCollection.as(...) adapters (Jackson/Java) and introduce envelope-level predicate support in CloudEvent filtering.

Reviewed changes

Copilot reviewed 13 out of 15 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
impl/model/src/main/java/io/serverlessworkflow/impl/model/jackson/JacksonModelCollection.java Adds richer as(Class<T>) conversions (List/Set/arrays) for Jackson-backed collections.
impl/json-utils/src/test/java/io/serverlessworkflow/impl/jackson/JsonUtilsStaticInitTest.java New test ensuring JsonUtils.mapper() reflects dynamic ObjectMapperFactoryProvider overrides.
impl/json-utils/src/test/java/io/serverlessworkflow/impl/jackson/JacksonCloudEventUtilsTest.java New tests covering CloudEvent/CloudEventData JSON round-trips and JsonUtils integration.
impl/json-utils/src/main/java/io/serverlessworkflow/impl/jackson/ObjectMapperFactoryProvider.java Introduces a default singleton mapper with CloudEvents module registration.
impl/json-utils/src/main/java/io/serverlessworkflow/impl/jackson/JsonUtils.java Removes static mapper caching; adds CloudEvent/CloudEventData special-casing.
impl/json-utils/src/main/java/io/serverlessworkflow/impl/jackson/JacksonCloudEventUtils.java Switches CloudEvent JSON handling to CloudEvents SDK’s official JSON event format.
impl/json-utils/pom.xml Adds/aligns test dependencies for the json-utils module.
impl/core/src/main/java/io/serverlessworkflow/impl/events/DefaultCloudEventPredicate.java Adds envelope predicate support via a reserved additional-property key.
experimental/test/src/test/java/io/serverlessworkflow/fluent/test/FuncEventFilterTest.java Expands tests to validate collection adapters (ArrayNode/List/Set/array).
experimental/pom.xml Formatting-only dependency indentation fix.
experimental/model/src/main/java/io/serverlessworkflow/impl/model/func/JavaModelCollection.java Extends as(Class<T>) conversions (List/Set/arrays) for Java-backed collections.
experimental/lambda/src/test/java/io/serverless/workflow/impl/executors/func/TraceExecutionListener.java New listener used by lambda tests to trace lifecycle events.
experimental/lambda/src/test/java/io/serverless/workflow/impl/executors/func/EventFilteringTest.java New end-to-end test validating event filtering behavior around instance-id extension matching.
experimental/lambda/pom.xml Formatting-only dependency indentation fix.
experimental/fluent/func/src/main/java/io/serverlessworkflow/fluent/func/FuncEventFilterPropertiesBuilder.java Routes envelope predicates into additionalProperties under envelopePredicate.

💡 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>
Copilot AI review requested due to automatic review settings March 30, 2026 23:09
Copy link
Copy Markdown
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 16 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Signed-off-by: Ricardo Zanini <ricardozanini@gmail.com>
… lazy init mapper

Signed-off-by: Ricardo Zanini <ricardozanini@gmail.com>
Copilot AI review requested due to automatic review settings March 31, 2026 16:00
Copy link
Copy Markdown
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 16 out of 17 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Signed-off-by: Ricardo Zanini <ricardozanini@gmail.com>
Comment on lines +76 to +78
if (properties.getAdditionalProperties() != null
&& properties.getAdditionalProperties().containsKey(ENVELOPE_PREDICATE))
envelopePredObj = properties.getAdditionalProperties().remove(ENVELOPE_PREDICATE);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
if (properties.getAdditionalProperties() != null
&& properties.getAdditionalProperties().containsKey(ENVELOPE_PREDICATE))
envelopePredObj = properties.getAdditionalProperties().remove(ENVELOPE_PREDICATE);
if (properties.getAdditionalProperties() != null) {
envelopePredObj = properties.getAdditionalProperties().remove(ENVELOPE_PREDICATE);
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Since envelopePredObje is checked againts null later, there is not need to call containsKey here

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We need it, otherwise remove will explode if the key is not present. It's a safer guardrail.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Probably this should have been an additional test to FuncEventFilterTest class

&& typeFilter.test(event.getType(), workflow, task)
&& dataSchemaFilter.test(event.getDataSchema(), workflow, task)
&& timeFilter.test(event.getTime(), workflow, task)
&& envelopeFilter.test(event, workflow, task)
Copy link
Copy Markdown
Collaborator

@fjtirado fjtirado Mar 31, 2026

Choose a reason for hiding this comment

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

hmmm, probably if there is an envelopeFilter, meaning a filter over the whole cloud event, the other filters (which are filtering the cloud event attributes, including the extensions) do no make much sense, but, who knows ;)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes, I was thinking about this one. Perhaps in the DSL we should solve this by filtering only the extension. But indeed having a way to pass the whole cloudEvent, users could do whatever they need with the envelope.

@fjtirado fjtirado merged commit 42e89a8 into serverlessworkflow:main Apr 1, 2026
3 checks passed
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.

Fix static ObjectMapper initialization trap in JsonUtils and add native CloudEvents Jackson support

3 participants