The solution that worked for me:
The serialized class and properties would be decorated as follows:
[DataContract]
public class MyDataClass
{
[DataMember(Name = "LabelInJson", IsRequired = false)]
public string MyProperty { get; set; }
}
IsRequired was the key item.
The actual serialization could be done using DataContractJsonSerializer:
public static string Serialize<T>(T obj)
{
string returnVal = "";
try
{
DataContractJsonSerializer serializer = new DataContractJsonSerializer(obj.GetType());
using (MemoryStream ms = new MemoryStream())
{
serializer.WriteObject(ms, obj);
returnVal = Encoding.Default.GetString(ms.ToArray());
}
}
catch (Exception exception)
{
retVal = "";
//log error
}
return returnVal;
}