Bugzilla – Bug 661919
DataContractJsonSerializer doesn't deserialize non-null values for nullable members properly
Last modified: 2011-07-31 18:01:09 UTC
Description of Problem: The DataContractJsonSerializer is filling nullable value types with 0 instead of the true value even when a value is provided. I would expect the nullable value type to default to null if not provided within the stream else be set to value provided by the stream. Steps to reproduce the problem: 1. [DataContract] public class c { public c() { } [DataMember] public int? parm_id { get; set; } [DataMember] public decimal? val { get; set; } } 2. string js = "{\"parm_id\":2}"; Use DataContractJsonSerializer to fill an instance with js. Actual Results: parm_id contains 0. val contains 0 Expected Results: parm_id should contain 2. val should contain null. How often does this happen? Everytime. Additional Information: Native windows returns expected results.
The issue is in DataContractJsonSerializer, which is not in System.Web.Extensions but in System.ServiceModel.Web (.NET 3.5) or System.Runtime.Serialization (.NET 4.0) Also, the results are different using the attached test case to those described in the report. parm_id is assigned 0 (wrong) but val is assigned null (correct).
Created attachment 406709 [details] test.cs
Thanks for detailing/clarifying the test case. Chris