Exclude Activity from being serialized in instance and execution log #4464
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR fixes an issue where the HTTP Request activity contains input properties containing IActivity instances, which shouldn't be serialized as part of the workflow instance or eecution log records.
Ideally, we could add a custom JSON converter that ignores IActivity instances, but since I need more time to figure that one out properly, I added an extensibility point to the WorkflowStateSerializer and SafeSerializer services to allow modules to add specialized custom converters, which fixes the issue with HTTP Request at hand.
=== auto-pr-body ===
Summary:
This Pull Request adds a new Elsa project ("Elsa.Samples.AspNet.DocumentApproval") to the solution, updates GlobalSection(SolutionConfigurationPlatforms) and GlobalSection(NestedProjects) in the Elsa.sln file, and refactors the DapperActivityExecutionRecordStore.cs file by converting synchronous methods to asynchronous methods. Additionally, methods in ActivityExecutionRecord, EFCoreActivityExecutionStore, WorkflowExecutionLogStore, ConfigureWorkflowStateSerialization.cs, HttpStatusCodeCaseForWorkflowInstanceConverter.cs, InputDescriptor, JsonIgnoreCompositeRootConverter.cs, ActivityDescriber.cs, JsonWorkflowStateSerializer.cs, and SafeSerializer.cs are updated to include the use of asynchronous methods and the addition of boolean variables
IsSerializable
in their implementations.List of Changes:
Read
method inHttpStatusCodeCaseConverter
to deserialize the HTTP status codeInputAttribute
andOutputAttribute
by adding boolean variablesIsSerializable
ISafeSerializer
to includeSerializeAsync
andDeserializeAsync
functions withCancellationToken
parameterISafeSerializerConfigurator
to configure the serializerActivityExecutionContextExtensions
to includeIsSerializable
when evaluating and completing input/output properties and outcomesIsSerializable
inInputDescriptor
classElsa.Mediator.Contracts
,Elsa.Workflows.Core.Notifications
public string Serialize(object? value)
topublic async ValueTask<string> SerializeAsync(object? value, CancellationToken cancellationToken = default)
public T Deserialize<T>(string json)
topublic async ValueTask<T> DeserializeAsync<T>(string json, CancellationToken cancellationToken = default)
Refactoring Targets:
Write
inHttpStatusCodeCaseConverter
by using a dictionary instead of an array to store the property valuesSerialize
andDeserialize
methods in theISafeSerializer
interface with theirasync
counterpartsActivityExecutionContextExtensions
with ternary operator to improve readability and reduce the number of lines of codeJsonWorkflowStateSerializer.cs
to be more DRY and move shared logic to helper functions.SerializingWorkflowState.cs
notification record toNotifications
folder, which could increase the readability and organization of the code.JsonSerializerOptions
to its own method, instead of it being insideCreateOptions
.