JSONMarshalled not working in Delphi

我们两清 提交于 2019-12-10 21:09:13

问题


I have the following simple class using Delphi XE7

{$M+}
{$RTTI EXPLICIT FIELDS([vcPrivate])}
TEntityForCreation = class
private
  [JSONMarshalled(False)]
  FCreator: Integer;
  FDescription: String;
public
  property Creator: Integer read FCreator write FCreator;
  property Description: String read FDescription write FDescription;
  function ToJsonString: string;
  class function FromJsonString(AJsonString: string): TEntityForCreation;
end;

The method ToJsonString uses the built in JSON serializing

function TEntityForCreation.ToJsonString: string;
begin
  result := TJson.ObjectToJsonString(self);
end;

For some reason, the Creator element is always being serialized in the Json string. I have turned "Emit Run Time Type information" to True in the project options.

Stepping through the JSON marshalling code, I see it is just not recognizing that the JSONMarshalled is linked to FCreator. I figure I am missing some compiler directive somewhere, but cannot figure it out.

来源:https://stackoverflow.com/questions/29931434/jsonmarshalled-not-working-in-delphi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!