❔ JsonDeserializer letting null for string type
Hi! I'm facing an issue where when deserializing json, the parser allows a null for string which breaks my app. Can i somehow specify that it is not to be null?
9 Replies
because i do have an error handling for deserialization that I'd like it to fall under
but it's not throwing an exception
is nullability enabled?
are you using
System.Text.Json
?Yup! And as for nulability I did not see anywhere a setting for that and google showed no results
there's a property for msbuild called
Nullable
, you set it in the csproj fileOh, pesimistic optimistic nullability
thought you were talking about global System.Text.Json settings
rn I have
<Nullable>enable</Nullable>
I assume i should do false
?Nullable reference type annotation should not change the meaning of code, I don’t think STJ has option for disallowing null. You probably need to use custom serialization contract or throw exception from constructor/property setter for null.
Oh, shame. I've tried such approach but seemed very verbose. Since it's more of a pet peeve than an actual appearing bug I guess I'll go without it.
Thank you for your help ❤️
No problem, looks like the idea itself is exist as issue here https://github.com/dotnet/runtime/issues/1256 but not implemented
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.