Closed GoogleCodeExporter closed 9 years ago
I would go even further, and make it customizable in TSuperRTTIContext:
- Include fields or not (and for which visibility)
- Include properties or not (and for which visibility)
Reason:
if you have classes from a legacy implementation which you want to expose using
a JSON RPC, you're probably not interested in the (private) fields, but more in
the published properties.
Original comment by mich...@freepascal.org
on 27 Mar 2012 at 7:23
I've implemented the SOIgnore attribute and as michael suggested the visibility
filters for fields and properties. I've attached the modified file.
usage:
TPerson = class
private
PrivateField: string;
public
Name: string;
Surname: string;
[SOIgnore]
BirthDate: TDateTime;
Address: string;
end;
ctx := TSuperRttiContext.Create;
try
ctx.FieldsVisibility := [mvPublic, mvPublished];
ctx.PropertiesVisibility := [mvPublic, mvPublished];
personStr := person.ToJson(ctx).AsString;
WriteLn(personStr);
personStr := StringReplace(personStr, '"Surname":"Doe",', '', []);
personCopy := TPerson.FromJson(personStr, ctx);
WriteLn(personCopy.Name);
finally
FreeAndNil(ctx);
end;
Original comment by Lee.Nover
on 4 Apr 2013 at 5:17
Attachments:
That looks great, I've certainly missed that. But where do I find the unit
"Reflection" that you are using...?
Kind regards,
Dan
Original comment by danander...@gmail.com
on 10 Oct 2013 at 12:03
Original issue reported on code.google.com by
dougcu...@gmail.com
on 6 Jun 2011 at 8:49