Skip to content

Deserialization with RespectNullableAnnotations = true does not treat undefined as null #49298

@Liversage

Description

@Liversage

Type of issue

Missing information

Description

JavaScript distinguishes between null and undefined and when JSON is deserialized a missing value becomes undefined. However, undefined does not exist in .NET and a missing string or object value deserializes to .NET null. This can lead to confusion when setting RespectNullableAnnotations to true because if the JSON value is missing, no exception is thrown when the target property is non-nullable leading to the property being null despite the setting. I think this article could be improved by explaining this.

Even better, it would be nice if JSON deserialization could be configured to treat a missing value the same way as null when deserializing to a non-null string or object. 🙏 Yes, I know this is not a documentation issue, but I had to mention it. 😀

Page URL

https://learn.microsoft.com/en-us/dotnet/standard/serialization/system-text-json/nullable-annotations

Content source URL

https://github.com/dotnet/docs/blob/main/docs/standard/serialization/system-text-json/nullable-annotations.md

Document Version Independent Id

7ae3d826-764a-2c29-a251-1a237beedd1a

Platform Id

5aacc351-ddac-0ce8-57df-aabac452d55b

Article author

@gewarren

Metadata

  • ID: 44d16e49-e10a-92b0-147e-a46542aefd51
  • PlatformId: 5aacc351-ddac-0ce8-57df-aabac452d55b
  • Service: dotnet-fundamentals

Related Issues

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions