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.
This commit is contained in:
parent
796438c51b
commit
2448d5eabd
|
|
@ -5,6 +5,7 @@ using Elsa.Workflows.Attributes;
|
|||
using Elsa.Workflows.Behaviors;
|
||||
using Elsa.Workflows.Contracts;
|
||||
using Elsa.Workflows.Models;
|
||||
using Elsa.Workflows.UIHints;
|
||||
using JetBrains.Annotations;
|
||||
|
||||
namespace Elsa.Workflows.Activities;
|
||||
|
|
@ -69,7 +70,7 @@ public class While : Activity
|
|||
/// <summary>
|
||||
/// The condition to evaluate.
|
||||
/// </summary>
|
||||
[Input(AutoEvaluate = false)]
|
||||
[Input(AutoEvaluate = false, UIHint = InputUIHints.SingleLine)]
|
||||
public Input<bool> Condition { get; set; } = new(false);
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using Elsa.Expressions.Contracts;
|
||||
|
|
@ -24,6 +25,7 @@ public class InputJsonConverter<T> : JsonConverter<Input<T>>
|
|||
public override bool CanConvert(Type typeToConvert) => typeof(Input).IsAssignableFrom(typeToConvert);
|
||||
|
||||
/// <inheritdoc />
|
||||
[UnconditionalSuppressMessage("Trimming", "IL2026:Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code", Justification = "<Pending>")]
|
||||
public override Input<T> Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||
{
|
||||
if (!JsonDocument.TryParseValue(ref reader, out var doc))
|
||||
|
|
@ -42,11 +44,17 @@ public class InputJsonConverter<T> : JsonConverter<Input<T>>
|
|||
var memoryBlockReference = expressionDescriptor?.MemoryBlockReferenceFactory();
|
||||
var memoryBlockReferenceType = memoryBlockReference?.GetType();
|
||||
var expressionValueElement = expressionElement.TryGetProperty("value", out var expressionElementValueValue) ? expressionElementValueValue : default;
|
||||
var expressionValue = expressionValueElement.ValueKind == JsonValueKind.String
|
||||
? expressionValueElement.GetString()
|
||||
: expressionValueElement.ValueKind != JsonValueKind.Undefined && memoryBlockReferenceType != null
|
||||
? expressionValueElement.Deserialize(memoryBlockReferenceType, options)!
|
||||
: default;
|
||||
|
||||
var expressionValue = expressionValueElement.ValueKind switch
|
||||
{
|
||||
JsonValueKind.String => expressionValueElement.GetString(),
|
||||
JsonValueKind.False => false,
|
||||
JsonValueKind.True => true,
|
||||
JsonValueKind.Number => expressionValueElement.GetDouble(),
|
||||
JsonValueKind.Undefined => default,
|
||||
_ => memoryBlockReferenceType != null ? expressionValueElement.Deserialize(memoryBlockReferenceType, options)! : default
|
||||
};
|
||||
|
||||
var expression = new Expression(expressionTypeName, expressionValue);
|
||||
|
||||
if (memoryBlockReference == null)
|
||||
|
|
|
|||
Loading…
Reference in a new issue