marlonnardi / JsonToDelphi

generate delphi classes from json (Json To Delphi Class Generator / JSON Data Binding Tool FMX, VCL and uniGUI)
https://jsontodelphi.com
64 stars 25 forks source link

Problem on convert TList<string> to Json #2

Closed fabriciohausman closed 2 years ago

fabriciohausman commented 2 years ago

There is a problem when convert class with TList property to json. The helper not assign TList property value to TArray variable.

sample:

TAttributes = class(TJsonDTO) private FId: Integer; FName: string; [JSONName('options')] FOptionsArray: TArray; [JSONMarshalled(False)] FOptions: TList; FPosition: Integer; FVariation: Boolean; FVisible: Boolean; function GetOptions: TList; procedure SetOptions(const Value: TList); protected function GetAsJson: string; override; published property Id: Integer read FId write FId; property Name: string read FName write FName; property Options: TList read GetOptions; property Position: Integer read FPosition write FPosition; property Variation: Boolean read FVariation write FVariation; property Visible: Boolean read FVisible write FVisible; public destructor Destroy; override; end;

... FTest := TAttributes.Create; FTest.Name := 'Teste'; FTest.Options.Add('Value1');

FTest.AsJson;

result is:

  {
     "id":0,
     "name":"Cor",
     "options":[

     ],
     "position":0,
     "variation":true,
     "visible":true
  }

for To correct i'm need write: FTest.Options.AsJson;

Somebody know if this is a bug or I not implemented right?

marlonnardi commented 2 years ago

Fixed, regenerate the classes from https://jsontodelphi.com and download the updated class Pkg.Json.DTO.pas