private member in the base class is not serialized.

Jan 15, 2010 at 8:49 AM

The document say that JsonPropertyAttribute can Includes non-public properties in serialization and deserialization.

but it seems that the private member in the base class is not serialized.

in following class, the A1 will not be serialized.

Is it bug?

 

        [JsonObject(MemberSerialization.OptIn)]
        public class A
        {
            [JsonProperty("A1")]
            private string _A1;
            public string A1 { get { return _A1; } set { _A1 = value; } }
            public string A2 { get; set; }
        }
        [JsonObject(MemberSerialization.OptIn)]
        public class A
        {
            [JsonProperty("A1")]
            private string _A1;
            public string A1 { get { return _A1; } set { _A1 = value; } }
        }

        [JsonObject(MemberSerialization.OptIn)]
        public class B : A
        {
            public string B1 { get; set; }

            [JsonProperty("B2")]
            string _B2;
            public string B2 { get{return _B2;} set{_B2=value;} }
	}

 

Coordinator
Jan 16, 2010 at 6:25 AM

Fixed.