Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem deserializing TList<String> #421

Closed
ads69 opened this issue Sep 17, 2020 · 2 comments
Closed

Problem deserializing TList<String> #421

ads69 opened this issue Sep 17, 2020 · 2 comments
Assignees
Labels
accepted Issue has been accepted and inserted in a future milestone
Milestone

Comments

@ads69
Copy link

ads69 commented Sep 17, 2020

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

@danieleteti
Copy link
Owner

Now it should be fixed. Let me know.

@danieleteti danieleteti self-assigned this Sep 21, 2020
@danieleteti danieleteti added the accepted Issue has been accepted and inserted in a future milestone label Sep 21, 2020
@danieleteti danieleteti added this to the 3.2.1-carbon milestone Sep 21, 2020
@ads69
Copy link
Author

ads69 commented Sep 21, 2020

Hi Daniele,
it's fixed.
Thanks

@ads69 ads69 closed this as completed Sep 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted Issue has been accepted and inserted in a future milestone
Projects
None yet
Development

No branches or pull requests

2 participants