Bug 13485 - DataContractJsonSerializer Does Not Deserialize Private Properties
Summary: DataContractJsonSerializer Does Not Deserialize Private Properties
Alias: None
Product: Class Libraries
Classification: Mono
Component: mscorlib ()
Version: unspecified
Hardware: PC Windows
: Normal major
Target Milestone: Untriaged
Assignee: Atsushi Eno
Depends on:
Reported: 2013-07-25 16:20 UTC by Anuj Bhatia
Modified: 2013-08-05 02:37 UTC (History)
5 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Anuj Bhatia 2013-07-25 16:20:50 UTC
When communicating using JSON protocol, deserialization fails to setup private properties marked with "DataMember" attribute. It does however work with protected or internal properties. This is different from how .Net handles it (.NET DataContractJsonDeserializer can deserialize into private properties as well).

Sample code:

public class TestJsonClass
public string Name { get; set; }

private string Value { get; set; }

public string GetValue { get { return this.Value; } }

public string ParseJson()
const string json = "{ \"Name\" : \"Test\", \"Value\" : \"ValueA\" }";

string result = string.Empty;

var serializer = new DataContractJsonSerializer(typeof(TestJsonClass));
TestJsonClass entity;
using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(json)))
entity = (TestJsonClass)serializer.ReadObject(stream);

result = entity.GetValue;
catch (Exception exception)
result = exception.ToString();

return result;

Expected Result : Result is set to "Test"
Actual: Result is null.
Comment 1 Miguel de Icaza [MSFT] 2013-08-02 19:47:10 UTC
Atsushi, can you take a look?
Comment 2 Atsushi Eno 2013-08-05 01:57:43 UTC
That's strange. What do you mean by System.Json "from Microsoft" ? We use System.Json from Microsoft now, right?
Comment 3 Atsushi Eno 2013-08-05 01:59:11 UTC
nm, it was not about System.Json. System.ServiceModel.Web. I totally forgot those things nowadays. Going to read code from scratch.
Comment 4 Atsushi Eno 2013-08-05 02:37:38 UTC
Fixed in mono master [8a10b06]