RE: Serialize X++ objects to JSON
In case anyone finds this. The output is empty because Newtonsoft is deliberately ignoring your data members.
The x compiler takes each DataMember attribute and makes a dotnet property out of it. That property is marked as "compiler generated", and Json.net will ignore compiler generated properties by default.
So, to serialise/deserialise an x object you have to tell Json.net to include compiler generated properties.
eg.
public static str Serialise(Object _obj)
{
Newtonsoft.Json.Serialization.DefaultContractResolver resolver = new Newtonsoft.Json.Serialization.DefaultContractResolver();
resolver.SerializeCompilerGeneratedMembers = true;
Newtonsoft.Json.JsonSerializerSettings settings = new Newtonsoft.Json.JsonSerializerSettings();
settings.ContractResolver = resolver;
return Newtonsoft.Json.JsonConvert::SerializeObject(_obj, settings);
}