Skip to content

Commit 2448d5e

Browse files
authored
Fix serialization of Boolean activity input (#4922)
* Improve InputJsonConverter handling and trimming suppression A new switch case block has been added for better handling of different types of JsonValueKind in InputJsonConverter. Also, a suppression message for the IL2026 trimming warning has been included to prevent potential runtime issues caused by code trimming, although justifications for this suppression are still pending. * Add UIHint to While activity's Condition input The Condition input in the While activity in Elsa.Workflows.Core has been updated to also include a UIHint. This aims to improve user input by specifically defining it as a SingleLine type.
1 parent 796438c commit 2448d5e

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

src/modules/Elsa.Workflows.Core/Activities/While.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using Elsa.Workflows.Behaviors;
66
using Elsa.Workflows.Contracts;
77
using Elsa.Workflows.Models;
8+
using Elsa.Workflows.UIHints;
89
using JetBrains.Annotations;
910

1011
namespace Elsa.Workflows.Activities;
@@ -69,7 +70,7 @@ public While(Func<bool> condition, IActivity? body = default, [CallerFilePath] s
6970
/// <summary>
7071
/// The condition to evaluate.
7172
/// </summary>
72-
[Input(AutoEvaluate = false)]
73+
[Input(AutoEvaluate = false, UIHint = InputUIHints.SingleLine)]
7374
public Input<bool> Condition { get; set; } = new(false);
7475

7576
/// <summary>

src/modules/Elsa.Workflows.Core/Serialization/Converters/InputJsonConverter.cs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Diagnostics.CodeAnalysis;
12
using System.Text.Json;
23
using System.Text.Json.Serialization;
34
using Elsa.Expressions.Contracts;
@@ -24,6 +25,7 @@ public InputJsonConverter(IExpressionDescriptorRegistry expressionDescriptorRegi
2425
public override bool CanConvert(Type typeToConvert) => typeof(Input).IsAssignableFrom(typeToConvert);
2526

2627
/// <inheritdoc />
28+
[UnconditionalSuppressMessage("Trimming", "IL2026:Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code", Justification = "<Pending>")]
2729
public override Input<T> Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
2830
{
2931
if (!JsonDocument.TryParseValue(ref reader, out var doc))
@@ -42,11 +44,17 @@ public override Input<T> Read(ref Utf8JsonReader reader, Type typeToConvert, Jso
4244
var memoryBlockReference = expressionDescriptor?.MemoryBlockReferenceFactory();
4345
var memoryBlockReferenceType = memoryBlockReference?.GetType();
4446
var expressionValueElement = expressionElement.TryGetProperty("value", out var expressionElementValueValue) ? expressionElementValueValue : default;
45-
var expressionValue = expressionValueElement.ValueKind == JsonValueKind.String
46-
? expressionValueElement.GetString()
47-
: expressionValueElement.ValueKind != JsonValueKind.Undefined && memoryBlockReferenceType != null
48-
? expressionValueElement.Deserialize(memoryBlockReferenceType, options)!
49-
: default;
47+
48+
var expressionValue = expressionValueElement.ValueKind switch
49+
{
50+
JsonValueKind.String => expressionValueElement.GetString(),
51+
JsonValueKind.False => false,
52+
JsonValueKind.True => true,
53+
JsonValueKind.Number => expressionValueElement.GetDouble(),
54+
JsonValueKind.Undefined => default,
55+
_ => memoryBlockReferenceType != null ? expressionValueElement.Deserialize(memoryBlockReferenceType, options)! : default
56+
};
57+
5058
var expression = new Expression(expressionTypeName, expressionValue);
5159

5260
if (memoryBlockReference == null)

0 commit comments

Comments
 (0)