Fix #1275 - Improve CloudEvent and CloudEventData handling#1282
Fix #1275 - Improve CloudEvent and CloudEventData handling#1282fjtirado merged 7 commits intoserverlessworkflow:mainfrom
Conversation
Signed-off-by: Ricardo Zanini <ricardozanini@gmail.com>
Signed-off-by: Ricardo Zanini <ricardozanini@gmail.com>
There was a problem hiding this comment.
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
JsonUtilsfetch theObjectMapperdynamically and add explicitCloudEvent/CloudEventDataconversions via CloudEvents SDK utilities. - Add a default fallback
ObjectMapperthat 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.
impl/model/src/main/java/io/serverlessworkflow/impl/model/jackson/JacksonModelCollection.java
Outdated
Show resolved
Hide resolved
...ntal/lambda/src/test/java/io/serverless/workflow/impl/executors/func/EventFilteringTest.java
Show resolved
Hide resolved
...ntal/lambda/src/test/java/io/serverless/workflow/impl/executors/func/EventFilteringTest.java
Outdated
Show resolved
Hide resolved
...json-utils/src/main/java/io/serverlessworkflow/impl/jackson/ObjectMapperFactoryProvider.java
Show resolved
Hide resolved
impl/core/src/main/java/io/serverlessworkflow/impl/events/DefaultCloudEventPredicate.java
Show resolved
Hide resolved
.../lambda/src/test/java/io/serverless/workflow/impl/executors/func/TraceExecutionListener.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Ricardo Zanini <ricardozanini@gmail.com>
Signed-off-by: Ricardo Zanini <ricardozanini@gmail.com>
There was a problem hiding this comment.
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.
...json-utils/src/main/java/io/serverlessworkflow/impl/jackson/ObjectMapperFactoryProvider.java
Show resolved
Hide resolved
Signed-off-by: Ricardo Zanini <ricardozanini@gmail.com>
experimental/model/src/main/java/io/serverlessworkflow/impl/model/func/JavaModelCollection.java
Outdated
Show resolved
Hide resolved
experimental/model/src/main/java/io/serverlessworkflow/impl/model/func/JavaModelCollection.java
Outdated
Show resolved
Hide resolved
impl/model/src/main/java/io/serverlessworkflow/impl/model/jackson/JacksonModelCollection.java
Outdated
Show resolved
Hide resolved
...json-utils/src/main/java/io/serverlessworkflow/impl/jackson/ObjectMapperFactoryProvider.java
Outdated
Show resolved
Hide resolved
...json-utils/src/main/java/io/serverlessworkflow/impl/jackson/ObjectMapperFactoryProvider.java
Outdated
Show resolved
Hide resolved
… lazy init mapper Signed-off-by: Ricardo Zanini <ricardozanini@gmail.com>
There was a problem hiding this comment.
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.
impl/core/src/main/java/io/serverlessworkflow/impl/CollectionConversionUtils.java
Show resolved
Hide resolved
Signed-off-by: Ricardo Zanini <ricardozanini@gmail.com>
| if (properties.getAdditionalProperties() != null | ||
| && properties.getAdditionalProperties().containsKey(ENVELOPE_PREDICATE)) | ||
| envelopePredObj = properties.getAdditionalProperties().remove(ENVELOPE_PREDICATE); |
There was a problem hiding this comment.
| 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); | |
| } |
There was a problem hiding this comment.
Since envelopePredObje is checked againts null later, there is not need to call containsKey here
There was a problem hiding this comment.
We need it, otherwise remove will explode if the key is not present. It's a safer guardrail.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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 ;)
There was a problem hiding this comment.
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.
Fix #1275
WIP