diff --git a/src/modules/Elsa.Expressions/Models/ExpressionDescriptor.cs b/src/modules/Elsa.Expressions/Models/ExpressionDescriptor.cs
index 8f42206606..b63ac9d7a7 100644
--- a/src/modules/Elsa.Expressions/Models/ExpressionDescriptor.cs
+++ b/src/modules/Elsa.Expressions/Models/ExpressionDescriptor.cs
@@ -1,3 +1,4 @@
+using System.Text.Json;
using Elsa.Expressions.Contracts;
namespace Elsa.Expressions.Models;
@@ -7,6 +8,20 @@ namespace Elsa.Expressions.Models;
///
public class ExpressionDescriptor
{
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ public ExpressionDescriptor()
+ {
+ // Default deserialization function.
+ Deserialize = context =>
+ {
+ return context.JsonElement.ValueKind == JsonValueKind.Object
+ ? context.JsonElement.Deserialize((JsonSerializerOptions?)context.Options)!
+ : new Expression(context.ExpressionType, null!);
+ };
+ }
+
///
/// Gets or sets the syntax name.
///
@@ -41,9 +56,9 @@ public class ExpressionDescriptor
/// Gets or sets the memory block reference factory.
///
public Func MemoryBlockReferenceFactory { get; set; } = () => new MemoryBlockReference();
-
+
///
/// Gets or sets the expression deserialization function.
///
- public Func Deserialize { get; set; } = default!;
+ public Func Deserialize { get; set; } = default!;
}
\ No newline at end of file
diff --git a/src/modules/Elsa.Expressions/Models/ExpressionSerializationContext.cs b/src/modules/Elsa.Expressions/Models/ExpressionSerializationContext.cs
index f366531b46..d5da5c2c8e 100644
--- a/src/modules/Elsa.Expressions/Models/ExpressionSerializationContext.cs
+++ b/src/modules/Elsa.Expressions/Models/ExpressionSerializationContext.cs
@@ -2,4 +2,7 @@
namespace Elsa.Expressions.Models;
-public record ExpressionSerializationContext(JsonElement JsonElement, JsonSerializerOptions Options, Type MemoryBlockType);
\ No newline at end of file
+///
+/// Defines the context for expression serialization.
+///
+public record ExpressionSerializationContext(string ExpressionType, JsonElement JsonElement, JsonSerializerOptions Options, Type MemoryBlockType);
\ No newline at end of file
diff --git a/src/modules/Elsa.Workflows.Core/Serialization/Converters/InputJsonConverter.cs b/src/modules/Elsa.Workflows.Core/Serialization/Converters/InputJsonConverter.cs
index d259b0deb6..f311ec8c59 100644
--- a/src/modules/Elsa.Workflows.Core/Serialization/Converters/InputJsonConverter.cs
+++ b/src/modules/Elsa.Workflows.Core/Serialization/Converters/InputJsonConverter.cs
@@ -47,7 +47,7 @@ public override Input Read(ref Utf8JsonReader reader, Type typeToConvert, Jso
return default!;
var memoryBlockType = memoryBlockReference.GetType();
- var context = new ExpressionSerializationContext(expressionElement, options, memoryBlockType);
+ var context = new ExpressionSerializationContext(expressionTypeName!, expressionElement, options, memoryBlockType);
var expression = expressionDescriptor!.Deserialize(context);
return (Input)Activator.CreateInstance(typeof(Input), expression, memoryBlockReference)!;
diff --git a/src/modules/Elsa.Workflows.Management/Providers/DefaultExpressionDescriptorProvider.cs b/src/modules/Elsa.Workflows.Management/Providers/DefaultExpressionDescriptorProvider.cs
index df80d1ce98..86076cee73 100644
--- a/src/modules/Elsa.Workflows.Management/Providers/DefaultExpressionDescriptorProvider.cs
+++ b/src/modules/Elsa.Workflows.Management/Providers/DefaultExpressionDescriptorProvider.cs
@@ -62,9 +62,9 @@ private ExpressionDescriptor CreateVariableDescriptor()
memoryBlockReferenceFactory: () => new Variable(),
deserialize: context =>
{
- var expressionValueElement = context.JsonElement.TryGetProperty("value", out var expressionElementValueValue) ? expressionElementValueValue : default;
- var expressionValue = expressionValueElement.Deserialize(context.MemoryBlockType, context.Options);
- return new Expression("Variable", expressionValue);
+ var valueElement = context.JsonElement.TryGetProperty("value", out var v) ? v : default;
+ var value = valueElement.Deserialize(context.MemoryBlockType, context.Options);
+ return new Expression("Variable", value);
}
);
}
@@ -86,16 +86,12 @@ private static ExpressionDescriptor CreateDescriptor(
IsSerializable = isSerializable,
IsBrowsable = isBrowsable,
HandlerFactory = sp => ActivatorUtilities.GetServiceOrCreateInstance(sp),
- MemoryBlockReferenceFactory = memoryBlockReferenceFactory ?? (() => new MemoryBlockReference()),
- Deserialize = deserialize ??
- (context =>
- {
- return context.JsonElement.ValueKind == JsonValueKind.Object
- ? context.JsonElement.Deserialize((JsonSerializerOptions?)context.Options)!
- : new Expression(expressionType, null!);
- })
+ MemoryBlockReferenceFactory = memoryBlockReferenceFactory ?? (() => new MemoryBlockReference())
};
+ if (deserialize != null)
+ descriptor.Deserialize = deserialize;
+
if (monacoLanguage != null)
descriptor.Properties = new
{