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
Trying to deserialize a class having a bool property. I am getting an exception:
System.AggregateException
HResult=0x80131500
Message=One or more errors occurred. (The JSON value could not be converted to System.Boolean. Path: $.results[0].taskSnap | LineNumber: 0 | BytePositionInLine: 598.)
Source=System.Private.CoreLib
StackTrace:
at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
at System.Threading.Tasks.Task`1.get_Result()
at UnitTests.General.General.GetActivities() in E:\Entwicklung\matterialcore-client-library\UnitTests\General\General.cs:line 140
This exception was originally thrown at this call stack:
[External Code]
Inner Exception 1:
JsonException: The JSON value could not be converted to System.Boolean. Path: $.results[0].taskSnap | LineNumber: 0 | BytePositionInLine: 598.
Inner Exception 2:
InvalidOperationException: Cannot get the value of a token type 'Null' as a boolean.
This happens even though the deserializer options are set to IgnoreNullValues = true.
Configuration
Windows 10 64 bit
Visual Studio 19 16.8.0 Preview 6
System.Text.Json version 5.0.0-rc.2.20475.5
Project Type: Library .Net 5.0
Class
public class Activity
{
public Activity()
{}
[JsonPropertyName("id"), JsonInclude]
public long Id { get; internal set; }
[JsonPropertyName("taskSnap"), JsonInclude]
public bool TaskSnap { get; internal set; }
}
JSon String to deserialize
{
"id": 14114,
"taskSnap": null
}
Deserialization:
var x = JsonSerializer.Deserialize<Activity>(jsonString, new JsonSerializerOptions { IgnoreNullValues = true } );
Other information
If I change the property as follows, it works:
[JsonPropertyName("taskSnap"), JsonInclude]
public bool? TaskSnap { get; internal set; }
The text was updated successfully, but these errors were encountered:
Description
Trying to deserialize a class having a bool property. I am getting an exception:
This happens even though the deserializer options are set to IgnoreNullValues = true.
Configuration
Windows 10 64 bit
Visual Studio 19 16.8.0 Preview 6
System.Text.Json version 5.0.0-rc.2.20475.5
Project Type: Library .Net 5.0
Class
JSon String to deserialize
Deserialization:
var x = JsonSerializer.Deserialize<Activity>(jsonString, new JsonSerializerOptions { IgnoreNullValues = true } );
Other information
If I change the property as follows, it works:
The text was updated successfully, but these errors were encountered: