question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

JsonExtensionData should not include the null values that are real object properties.

See original GitHub issue

The exception in the code below should not be thrown. It should not add E to the extended property bag when there is a property called E already.

class Program
{
    static void Main(string[] args)
    {
        var a = JsonConvert.DeserializeObject<A>("{\"E\":null}", new JsonSerializerSettings
        {
            NullValueHandling = NullValueHandling.Ignore,
        });

        if (a.PropertyBag.ContainsKey("E"))
            throw new Exception("Not expected!");
    }

    class A
    {
        public B? E { get; set; }

        [JsonExtensionData]
        public IDictionary<string, object> PropertyBag { get; set; }
    }

    enum B
    {
        One,
        Two
    }
}

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
JamesNKcommented, Oct 9, 2018

Should be released in the next 2-4 weeks

1reaction
JamesNKcommented, Sep 22, 2018

I think if you ignore a value being set on a property then it makes sense that you wouldn’t want it in extension data. I also fixed it for default values.

Read more comments on GitHub >

github_iconTop Results From Across the Web

NullValueHandling.Ignore influences deserialization into ...
Reported in JsonExtensionData should not include the null values that are real object properties. #1719 and fixed in commit e079301.
Read more >
JsonExtensionDataAttribute Class (System.Text.Json. ...
During deserialization, when using Object, a "null" JSON value is treated as a null ... the name of the extension data property is...
Read more >
C# - How to use JsonExtensionData
Null check the JsonExtensionData property. When there's no additional properties in the JSON, the JsonExtensionData property will be null. Do a ...
Read more >
Migrate from Newtonsoft.Json to System.Text.Json - .NET
Json features, migration will not be possible without significant changes. ... all null-value or default-value properties should be ignored.
Read more >
Serialization Attributes
It includes non-public properties in serialization and deserialization. It can be used to customize type name, reference, null, and default value handling for ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found