You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Deserializing null to a non-option-wrapped type produces a different error message depending on whether the target type is a value or reference type:
letoptions= JsonSerializerOptions()
options.Converters.Add(JsonFSharpConverter())letdeserialize<'a>(str:string)= JsonSerializer.Deserialize<'a>(str, options)typeA={ A:int; B:string }
deserialize<A>"""{ "A": 2, "B": null }"""// System.Text.Json.JsonException: A.B was expected to be of type String, but was null.
deserialize<A>"""{ "A": null, "B": "a" }"""// System.Text.Json.JsonException: The JSON value could not be converted to System.Int32. Path: $ | LineNumber: 0 | BytePositionInLine: 4. Path: $ | LineNumber: 0 | BytePositionInLine: 6. ---> System.InvalidOperationException: Cannot get the value of a token type 'Null' as a number.
Perhaps this could be made consistent? Something like:
System.Text.Json.JsonException: Null is not allowed here. <path, line number, etc.>
(Of course, the path/line number/position is wrong, as detailed in #37).
I don't care that much about this issue, I just noticed it and wanted to mention it.
The text was updated successfully, but these errors were encountered:
cmeeren
changed the title
Consistency of error message when deserializing null to a value type
Consistency of error message when deserializing null to value vs. reference type
Jan 29, 2021
Deserializing
null
to a non-option
-wrapped type produces a different error message depending on whether the target type is a value or reference type:Perhaps this could be made consistent? Something like:
(Of course, the path/line number/position is wrong, as detailed in #37).
I don't care that much about this issue, I just noticed it and wanted to mention it.
The text was updated successfully, but these errors were encountered: