Search code examples
xmldelphidelphi-xe2pascalomnixml

Can OmniXML Deserialise an object containing a list of objects?


So for example how to serialise an object like this:

unit u_Configuration;

interface

uses
  Classes,
  Generics.Collections,
  OmniXML,
  OmniXMLPersistent
  ;

type
  TMyObject = class (TPersistent)
    strict private
      fName : String;
    public
    published
      property Name: String read fName write fName;
  end;

  TConfiguration = class(TPersistent)
    strict private
      fTheList : TList<TMyObject>;
    private
    public
    published
      property TheList: TList<TMyObject> read fTheList write fTheList;

  end;

implementation

end.

Solution

  • OmniXML serializes descendants of TPersistent. It serializes their properties, but for properties having object types, only descendants of TPersistent are serialized. TList descends from TEnumerable, which descends from TObject, so it doesn't qualify. OmniXML has special handling built in for TCollection.

    You can serialize other classes manually.