Bug 661919 - DataContractJsonSerializer doesn't deserialize non-null values for nullable members properly
Summary: DataContractJsonSerializer doesn't deserialize non-null values for nullable m...
Status: NEW
Alias: None
Product: Mono: Class Libraries
Classification: Mono
Component: WCF (show other bugs)
Version: 2.8.x
Hardware: i686 Linux
: P5 - None : Normal
Target Milestone: ---
Assignee: Atsushi Enomoto
QA Contact: Mono Bugs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-12-30 21:56 UTC by Forgotten User ZsvJbCwNxG
Modified: 2011-07-31 18:01 UTC (History)
1 user (show)

See Also:
Found By: ---
Services Priority:
Business Priority:
Blocker: ---
Marketing QA Status: ---
IT Deployment: ---


Attachments
test.cs (913 bytes, text/x-csharp)
2011-01-03 07:08 UTC, Marek Habersack
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Forgotten User ZsvJbCwNxG 2010-12-30 21:56:48 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.
Comment 1 Marek Habersack 2011-01-03 07:06:37 UTC
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).
Comment 2 Marek Habersack 2011-01-03 07:08:25 UTC
Created attachment 406709 [details]
test.cs
Comment 3 Forgotten User ZsvJbCwNxG 2011-01-03 19:36:41 UTC
Thanks for detailing/clarifying the test case. 
Chris