Delphi Superobject, generic list to json
I have a object with some TObjectList<>-fields that I try to encode as JSON with help form SuperObject.
TLogs = TObjectList<TLog>;
TMyObject = class(TObject)
private
FLogs: TLogs;
end;
Deep inside SuperObjects code, there is a ToClass procedure, iterating the fields and add them to the json result.
In this loop, there is a check on the TRttiFields FieldType. If it's nil, it skips the object.
for f in Context.GetType(Value.AsObject.ClassType).GetFields do
if f.FieldType <> nil then
begin
v :=开发者_运维技巧 f.GetValue(value.AsObject);
result.AsObject[GetFieldName(f)] := ToJson(v, index);
end
My generic list fields have a FieldType of nil. Why?
How can I make SuperObject serialize my list of objects?
This is a known issue in Delphi's RTTI creation. If you declare your generic class like that, it won't work. You need to use the class keyword.
TLogs = class(TObjectList<TLog>);
Hopefully this will be fixed in the next release.
精彩评论