Skip to content

How should we handle JsonSerializer.DeserializeAsync nullable return type? #60195

Answered by huoyaoyuan
0xced asked this question in Q&A
Discussion options

You must be logged in to vote

So, what does that mean? How can a result be null instead of an exception being thrown during deserialization?

If you pass a root literal null (the json text is null without quotation), it should be deserialized as null.

Generally, you should always verify bad input. Sometimes it's correctly formed, but the content of fields are bad. Nulls can be handled in the verification, together with null fields.

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@0xced
Comment options

Answer selected by 0xced
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants