问 题
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); endMy 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.
本文地址:IT屋 » Delphi Superobject, generic list to json
问 题
我有一个对象与一些TObjectList<> - 字段,我尝试编码为JSON的帮助形式 SuperObject 。
TLogs = TObjectList< TLog> ;;
TMyObject = class(TObject)
private
FLogs:TLogs;
结束
深入SuperObjects代码,有一个ToClass过程,迭代字段并将其添加到json结果
在这个循环中,有一个检查TRttiFields FieldType。如果没有,它会跳过对象。
for Context.GetType(Value.AsObject.ClassType).GetFields
如果f.FieldType<> nil then
begin
v:= f.GetValue(value.AsObject);
result.AsObject [GetFieldName(f)]:= ToJson(v,index);
end
我的通用列表字段的FieldType为零。为什么?
如何使SuperObject序列化我的对象列表?
解决方案
这是Delphi的RTTI创建中的一个已知问题。如果你这样宣告你的泛型类,那就不行了。您需要使用类关键字。
TLogs = class(TObjectList< TLog>);
希望这将在下一个版本中修复。
本文地址:IT屋 » Delphi Superobject,通用列表到json