Delphi Superobject, general list for json

I have an object with some TObjectList <> fields that I am trying to encode as JSON using the SuperObject form.

TLogs = TObjectList<TLog>; TMyObject = class(TObject) private FLogs: TLogs; end; 

Inside the SuperObjects code there is a ToClass procedure, iterating over the fields and adding them to the json result.

This loop checks the field type TRttiFields FieldType. If it is zero, 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 general field lists have FieldType from nil. Why?

How can I get SuperObject to serialize a list of objects?

+4
source share
1 answer

This is a known issue in creating Delphi RTTI. If you declare your generic class as such, it will not work. You need to use the class keyword.

 TLogs = class(TObjectList<TLog>); 

Hope this will be fixed in the next version.

+7
source

Source: https://habr.com/ru/post/1310510/


All Articles