❔ Why does the JsonSerializer.Deserialize return a nullable object
I found this following example in the docs about the deserializer:
based on the docs it looks like it would throw an exception if the json can't be deserialized. The type, for deserialization, in this case is
WeatherForecase
not WeatherForecast?
. Why does it return nullable<..>? Is there a way to make it return the acutal instance or just throw an error? I want to avoid many (maybe unnecessary) null checks?
Thx!4 Replies
because you can deserialize the string
null
yeah, the literal contents
is a valid json object
so if the input contains only that, then the deserialized object will also be null
ah I see, makes sense - thank you guys
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.