-
Notifications
You must be signed in to change notification settings - Fork 5k
Fix JsonValueConverter to handle array and object values in Dictionary<string, JsonValue> #115829
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,18 @@ | |
return null; | ||
} | ||
|
||
// For Object or Array types, return a JsonObject or JsonArray instance | ||
// when deserializing a JsonValue. This maintains compatibility with .NET 8.0. | ||
if (reader.TokenType is JsonTokenType.StartObject) | ||
{ | ||
return (JsonValue)JsonNodeConverter.ObjectConverter.Read(ref reader, typeof(JsonObject), options)!; | ||
Check failure on line 34 in src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Node/JsonValueConverter.cs
|
||
} | ||
|
||
Check failure on line 36 in src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Node/JsonValueConverter.cs
|
||
if (reader.TokenType is JsonTokenType.StartArray) | ||
{ | ||
return (JsonValue)JsonNodeConverter.ArrayConverter.Read(ref reader, typeof(JsonArray), options)!; | ||
Check failure on line 39 in src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Node/JsonValueConverter.cs
|
||
} | ||
|
||
JsonElement element = JsonElement.ParseValue(ref reader); | ||
return JsonValue.CreateFromElement(ref element, options.GetNodeOptions()); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove the invalid cast that is causing the build to fail.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed the invalid cast and replaced it with
as JsonValue
to correctly handle the type conversion. Fixed in 996f325.