Skip to content

Commit

Permalink
Fix json deserialization error on select value changed
Browse files Browse the repository at this point in the history
Due to .NET internal transformation of the provided JSON array, it can happen that ValueChanged receives a JsonElement of type String instead of Array, resulting in an error then trying to deserialize it into an array.
This commit fixes that.
  • Loading branch information
VolkerLieber committed Feb 1, 2024
1 parent 0b5584e commit 95e2d37
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions SiemensIXBlazor/Components/Select/Select.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,14 @@ public async void ValueChanged(dynamic labels)
else if(labels is JsonElement)
{
JsonElement jsonText = labels;
string[] labelArray = jsonText.Deserialize<string[]>()!;
await ValueChangeEvent.InvokeAsync(labelArray);

if (jsonText.ValueKind == JsonValueKind.Array) {
string[] labelArray = jsonText.Deserialize<string[]>()!;
await ValueChangeEvent.InvokeAsync(labelArray);
} else
{
await ValueChangeEvent.InvokeAsync(jsonText.GetString());
}
}

}
Expand Down

0 comments on commit 95e2d37

Please sign in to comment.