How can JsonSerializer.Deserialize ever return null? #77317
-
All of the overload methods for
I ask because in my code I'm doing the relevant type checks i.e if (deserializedObject is null)
{
// deal with T?...
} and when unit testing this code, I cant get a scenario where I can meet this condition. It then begs the question, if I have a feeling it might be to do with some JSON serialization options that aren't set by default that would return null rather than throwing in some cases, but I cant find anything that resembles this behavior in my own findings. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
E.g. using System.Text.Json;
object? obj = JsonSerializer.Deserialize<object>("null");
Console.WriteLine(obj is null); |
Beta Was this translation helpful? Give feedback.
E.g.