JsonExtensionData should not include the null values that are real object properties.
See original GitHub issueThe 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:
- Created 5 years ago
- Reactions:1
- Comments:8 (2 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Should be released in the next 2-4 weeks
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.