diff options
author | Atsushi Eno <atsushieno@veritas-vos-liberabit.com> | 2013-08-05 10:36:24 +0400 |
---|---|---|
committer | Atsushi Eno <atsushieno@veritas-vos-liberabit.com> | 2013-08-05 10:36:24 +0400 |
commit | 8a10b06610c67267d5f0940bdec8f0b64f478443 (patch) | |
tree | b901e30503ec5aeacf9ec61574c462e0bbea9208 /mcs/class/System.ServiceModel.Web | |
parent | 5a9472a254d59a94ef90d551fe76ef43821e5663 (diff) |
Fix bug #13485: retrieve private fields and properties in serialization.
Diffstat (limited to 'mcs/class/System.ServiceModel.Web')
2 files changed, 33 insertions, 6 deletions
diff --git a/mcs/class/System.ServiceModel.Web/System.Runtime.Serialization.Json/TypeMap.cs b/mcs/class/System.ServiceModel.Web/System.Runtime.Serialization.Json/TypeMap.cs index 67aaf7db84e..09886796b7f 100644 --- a/mcs/class/System.ServiceModel.Web/System.Runtime.Serialization.Json/TypeMap.cs +++ b/mcs/class/System.ServiceModel.Web/System.Runtime.Serialization.Json/TypeMap.cs @@ -81,10 +81,9 @@ namespace System.Runtime.Serialization.Json static TypeMap CreateDefaultTypeMap (Type type) { var l = new List<TypeMapMember> (); - foreach (var fi in type.GetFields ()) - if (!fi.IsStatic) - l.Add (new TypeMapField (fi, null)); - foreach (var pi in type.GetProperties ()) + foreach (var fi in type.GetFields (binding_flags)) + l.Add (new TypeMapField (fi, null)); + foreach (var pi in type.GetProperties (binding_flags)) if (pi.CanRead && pi.CanWrite && !pi.GetGetMethod ().IsStatic && pi.GetIndexParameters ().Length == 0) l.Add (new TypeMapProperty (pi, null)); l.Sort ((x, y) => x.Order != y.Order ? x.Order - y.Order : String.Compare (x.Name, y.Name, StringComparison.Ordinal)); @@ -116,7 +115,7 @@ namespace System.Runtime.Serialization.Json List<TypeMapMember> members = new List<TypeMapMember> (); - foreach (FieldInfo fi in type.GetFields (BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)) { + foreach (FieldInfo fi in type.GetFields (binding_flags)) { if (dca != null) { object [] atts = fi.GetCustomAttributes (typeof (DataMemberAttribute), true); if (atts.Length == 0) @@ -131,7 +130,7 @@ namespace System.Runtime.Serialization.Json } if (dca != null) { - foreach (PropertyInfo pi in type.GetProperties (BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)) { + foreach (PropertyInfo pi in type.GetProperties (binding_flags)) { object [] atts = pi.GetCustomAttributes (typeof (DataMemberAttribute), true); if (atts.Length == 0) continue; diff --git a/mcs/class/System.ServiceModel.Web/Test/System.Runtime.Serialization.Json/DataContractJsonSerializerTest.cs b/mcs/class/System.ServiceModel.Web/Test/System.Runtime.Serialization.Json/DataContractJsonSerializerTest.cs index 7a37a5b4e70..cba0fb87bc6 100644 --- a/mcs/class/System.ServiceModel.Web/Test/System.Runtime.Serialization.Json/DataContractJsonSerializerTest.cs +++ b/mcs/class/System.ServiceModel.Web/Test/System.Runtime.Serialization.Json/DataContractJsonSerializerTest.cs @@ -1452,6 +1452,21 @@ namespace MonoTests.System.Runtime.Serialization.Json Assert.AreEqual (1, dict.Count, "#2"); Assert.AreEqual ("value", dict ["key"], "#3"); } + + [Test] + public void Bug13485 () + { + const string json = "{ \"Name\" : \"Test\", \"Value\" : \"ValueA\" }"; + + string result = string.Empty; + var serializer = new DataContractJsonSerializer (typeof (Bug13485Type)); + Bug13485Type entity; + using (var stream = new MemoryStream (Encoding.UTF8.GetBytes (json))) + entity = (Bug13485Type) serializer.ReadObject (stream); + + result = entity.GetValue; + Assert.AreEqual ("ValueA", result, "#1"); + } } public class CharTest @@ -1762,3 +1777,16 @@ public class MyDictionary<K, V> : System.Collections.Generic.IDictionary<K, V> } } +[DataContract] +public class Bug13485Type +{ + [DataMember] + public string Name { get; set; } + + [DataMember (Name = "Value")] + private string Value { get; set; } + + public string GetValue { get { return this.Value; } } +} + + |