Hello ,
I would like to convert ax object to JSON
I used data contract serialization and add it to AOT .
namespace Demo
{
public class ContractSerializer
{
public static string Serialize(Object o)
{
Type type = o.GetType();
f (!Attribute.IsDefined(type, typeof(DataContractAttribute)))
{
throw new ArgumentException(String.Format("{0} is not a data contract", type.FullName));
}
var json = new JavaScriptSerializer().Serialize(o);
return json ;
}
}
}
}
This is Ax method to print json
[SysEntryPointAttribute]
public void serializeToInfolog()
{
DirPersonInfoData person = this.getPersonData();
System.Exception ex;
System.Object clrPerson;
str serialized;
if (!xSession::isCLRSession())
{
throw error("Must run CIL!");
}
try
{
clrPerson = CLRInterop::getObjectForAnyType(person);
serialized = strFmt("%1",Demo.ContractSerializer::Serialize(clrPerson));
}
catch (Exception::CLRError)
{
ex = CLRInterop::getLastException();
throw error(ex.ToString());
}
info(strFmt("%1",serialized));
}
**** It is working successfully but when i changed the the person info in the below method and run the class it is not take effect unless make Full CIL
private DirPersonInfoData getPersonData()
{
DirPersonInfoData person = new DirPersonInfoData();
person.parmPersonName("izuhair");
person.parmPersonPrimaryEmail("izuhair@smasco.com");
person.parmPersonUserId("Isam");
return person;
}