diff --git a/src/modules/Elsa.Expressions/Helpers/ObjectConverter.cs b/src/modules/Elsa.Expressions/Helpers/ObjectConverter.cs index fbbc11518..fb5a42059 100644 --- a/src/modules/Elsa.Expressions/Helpers/ObjectConverter.cs +++ b/src/modules/Elsa.Expressions/Helpers/ObjectConverter.cs @@ -3,6 +3,7 @@ using System.ComponentModel; using System.Dynamic; using System.Globalization; using System.Text.Json; +using System.Text.Json.Nodes; using System.Text.Json.Serialization; using Elsa.Expressions.Contracts; using Elsa.Expressions.Exceptions; @@ -70,15 +71,22 @@ public static class ObjectConverter var underlyingTargetType = Nullable.GetUnderlyingType(targetType) ?? targetType; var underlyingSourceType = Nullable.GetUnderlyingType(sourceType) ?? sourceType; - if (value is JsonElement jsonNumber && jsonNumber.ValueKind == JsonValueKind.Number && underlyingTargetType == typeof(string)) + if (value is JsonElement { ValueKind: JsonValueKind.Number } jsonNumber && underlyingTargetType == typeof(string)) return jsonNumber.ToString().ConvertTo(underlyingTargetType); - if (value is JsonElement jsonObject) + if (value is JsonElement jsonElement) { - if (jsonObject.ValueKind == JsonValueKind.String && underlyingTargetType != typeof(string)) - return jsonObject.GetString().ConvertTo(underlyingTargetType); + if (jsonElement.ValueKind == JsonValueKind.String && underlyingTargetType != typeof(string)) + return jsonElement.GetString().ConvertTo(underlyingTargetType); - return jsonObject.Deserialize(targetType, options); + return jsonElement.Deserialize(targetType, options); + } + + if (value is JsonObject jsonObject) + { + return underlyingTargetType == typeof(string) + ? jsonObject.ToString() + : jsonObject.Deserialize(targetType, options); } if (underlyingSourceType == typeof(string) && !underlyingTargetType.IsPrimitive && underlyingTargetType != typeof(object))