danieleteti / delphimvcframework

DMVCFramework (for short) is a popular and powerful framework for WEB API in Delphi. Supports RESTful and JSON-RPC WEB APIs development.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Problem deserializing TList<String>

ads69 opened this issue · comments

commented

Hi,

I have a class like that

Type

  TBitbucketPath = Class
  Private
    FComponents: TList<String>;
    FExtension: String;
    FName: String;
    FParent: String;
    FToString: String;
  Public
    Property components: TList < String > Read FComponents Write FComponents;
    Property extension: String Read FExtension Write FExtension;
    Property name: String Read FName Write FName;
    Property parent: String Read FParent Write FParent;
    Property toString: String Read FToString Write FToString;
    Constructor Create;
    Destructor Destroy; Override;
  End;

  TBitbucketValue = Class
  Private
    FContentId: String;
    FPath: TBitbucketPath;
    FSize: Integer;
    FType: String;
  Public
    Property contentId: String Read FContentId Write FContentId;
    Property path: TBitbucketPath Read FPath Write FPath;
    Property size: Integer Read FSize Write FSize;
    Property &type: String Read FType Write FType;
    Constructor Create;
    Destructor Destroy; Override;
  End;

  TBitbucketChildren = Class
  Private
    FIsLastPage: Boolean;
    FLimit: Integer;
    FSize: Integer;
    FStart: Integer;
    FValues: TObjectList<TBitbucketValue>;
  Public
    Property isLastPage: Boolean Read FIsLastPage Write FIsLastPage;
    Property limit: Integer Read FLimit Write FLimit;
    Property size: Integer Read FSize Write FSize;
    Property start: Integer Read FStart Write FStart;
    Property values: TObjectList < TBitbucketValue > Read FValues Write FValues;

    Constructor Create;
    Destructor Destroy; Override;
  End;

  TBitbucketMain = Class
  Private
    FComponents: TList<String>;
    FName: String;
    FParent: String;
    FToString: String;
  Public
    Property components: TList < String > Read FComponents Write FComponents;
    Property name: String Read FName Write FName;
    Property parent: String Read FParent Write FParent;
    Property toString: String Read FToString Write FToString;
    Constructor Create;
    Destructor Destroy; Override;
  End;

  TBitBucketBrowse = Class
  Private
    FChildren: TBitbucketChildren;
    FPath: TBitbucketMain;
    FRevision: String;
  Public
    Property children: TBitbucketChildren Read FChildren Write FChildren;
    Property path: TBitbucketMain Read FPath Write FPath;
    Property revision: String Read FRevision Write FRevision;
    Constructor Create;
    Destructor Destroy; Override;
  End;

Implementation

{TBitbucketPath}

Constructor TBitbucketPath.Create;
Begin
  Inherited;
  FComponents := TList<String>.Create;
End;

Destructor TBitbucketPath.Destroy;
Begin
  If FComponents <> Nil Then
    FreeAndNil(FComponents);
  Inherited;
End;

{TBitbucketValue}

Constructor TBitbucketValue.Create;
Begin
  Inherited;
  FPath := TBitbucketPath.Create();
End;

Destructor TBitbucketValue.Destroy;
Begin
  If FPath <> Nil Then
    FreeAndNil(FPath);
  Inherited;
End;

{TBitbucketChildren}

Constructor TBitbucketChildren.Create;
Begin
  Inherited;
  FValues := TObjectList<TBitbucketValue>.Create;
End;

Destructor TBitbucketChildren.Destroy;
Begin
  If FValues <> Nil Then
    FreeAndNil(FValues);

  Inherited;
End;

{TBitbucketMain}

Constructor TBitbucketMain.Create;
Begin
  Inherited;
  FComponents := TList<String>.Create;
End;

Destructor TBitbucketMain.Destroy;
Begin
  If FComponents <> Nil Then
    FreeAndNil(FComponents);
  Inherited;
End;

{TBitBucketBrowse}

Constructor TBitBucketBrowse.Create;
Begin
  Inherited;
  FPath := TBitbucketMain.Create();
  FChildren := TBitbucketChildren.Create();
End;

Destructor TBitBucketBrowse.Destroy;
Begin
  If FPath <> Nil Then
    FreeAndNil(FPath);

  If FChildren <> Nil Then
    FreeAndNil(FChildren);
  Inherited;
End;

Now I have for testing

Var S:String;
BB: TBitBucketBrowse;
Begin
BB := TBitBucketBrowse.Create;
BB.path.components.Add('Test 1');
BB.path.components.Add('Test 2');
S:=GetDefaultSerializer.SerializeObject(BB); //this is ok
GetDefaultSerializer.DeserializeObject(S, BB);

This raise an error
Invalid class typecast for property "components" [Expected: TList<System.string>, Actual: Array]

Best regards

Armindo

Now it should be fixed. Let me know.

commented

Hi Daniele,
it's fixed.
Thanks