Closed fabriciohausman closed 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?
Fixed, regenerate the classes from https://jsontodelphi.com and download the updated class Pkg.Json.DTO.pas
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:
for To correct i'm need write: FTest.Options.AsJson;
Somebody know if this is a bug or I not implemented right?