问题
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