the below code gives you json = '{"Name":"Test","Id":1,"MyEnum":3}', when you have a non-null value.
public enum SerializeObjTestClassEnum
{
one = 1, two, three, four
}
[Serializable]
public class SerializeObjTestClass
{
public string Name { get; set; }
public int Id { get; set; }
public SerializeObjTestClassEnum MyEnum{ get; set; }
}
public void SerializeObject_Test_Basic_Object()
{
var obj = new SerializeObjTestClass { Id = 1, Name = "Test", MyEnum = SerializeObjTestClassEnum.three };
var json = (new JavaScriptSerializer()).Serialize(obj);
}
this code gives you json = '{"Name":"Test","Id":1,"MyEnum":0}'
var obj = new SerializeObjTestClass { Id = 1, Name = "Test" };
Notice how the enum, when not set, is serialized to a 0, while the enum itself starts out at 1. So this is how you code can know a NULL value was used for the enum.
if you want the json to look like '{"Name":"Test","Id":1,"MyEnum":null}', then you're going to need to fake it out by using a class wrapper around the Enum.