views:

222

answers:

1

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?

+5  A: 

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.

Mason Wheeler