PKGeorgiev / Delphi-JsonToDelphiClass

Generates Delphi Classes based on JSON string (Json To Delphi Class Generator / JSON Data Binding Tool)
MIT License
236 stars 122 forks source link

Problem with GetAsJson and RefreshArray #21

Open MatheusLetra opened 3 years ago

MatheusLetra commented 3 years ago

Ao gerar minha classe, obtenho os erros:

unit UPedido;

interface

uses Pkg.Json.DTO, System.Generics.Collections, REST.Json.Types;

{$M+}

type TProdutos = class private FDescricao: string; FId: Integer; FQtde: Integer; FUnitario: Double; published property Descricao: string read FDescricao write FDescricao; property Id: Integer read FId write FId; property Qtde: Integer read FQtde write FQtde; property Unitario: Double read FUnitario write FUnitario; end;

TPedido = class(TJsonDTO) private FCliente: string; FId: Integer; [JSONName('produtos'), JSONMarshalled(False)] FProdutosArray: TArray; [GenericListReflect] FProdutos: TObjectList; function GetProdutos: TObjectList; protected function GetAsJson: string; override; published property Cliente: string read FCliente write FCliente; property Id: Integer read FId write FId; property Produtos: TObjectList read GetProdutos; public destructor Destroy; override; end;

implementation

{ TPedido }

destructor TPedido.Destroy; begin GetProdutos.Free; inherited; end;

function TPedido.GetProdutos: TObjectList; begin Result := ObjectList(FProdutos, FProdutosArray); end;

function TPedido.GetAsJson: string; begin RefreshArray(FProdutos, FProdutosArray); Result := inherited; end;

end.

marlonnardi commented 3 years ago

Experimente usar o site https://jsontodelphi.com o mesmo possui vários novos recursos implementados para geração de classes em Delphi.

News and Fixes: https://github.com/marlonnardi/JsonToDelphi#jsontodelphi-online

JensBorrisholt commented 3 years ago

@MatheusLetra can you please provide me with the JSON?