I've been serializing custom type which has some internal properties but when serializing, it seems that using System.Web.Script.Serialization.JavaScriptSerializer
serialize
method do not serialize internal properties (as it skips the internal property in serialized string).
It can easily be understandable from the following code and output :
public class MyClass
{
public string Property1 { get; set; }
internal string Property2 { get; set; }
public string Property3 { get; set; }
}
JavaScriptSerializer mySerializer = new JavaScriptSerializer();
string jsonString = mySerializer.Serialize(new MyClass()
{
Property1 = "One",
Property2 = "Twp",
Property3 = "Three"
});
The jsonString has following value :
{"Property1":"One","Property3":"Three"}
In output, you can see that serialized string do not have Property2 which is internal property. Is there something logic behind it for not supporting internal property in serialization?
What would be the workaround to serialize internal property(except changing internal to public modifier)?