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 with GetAsJson and RefreshArray #21

Open
MatheusLetra opened this issue Aug 17, 2021 · 2 comments
Open

Problem with GetAsJson and RefreshArray #21

MatheusLetra opened this issue Aug 17, 2021 · 2 comments

Comments

@MatheusLetra
Copy link

Ao gerar minha classe, obtenho os erros:

  • [dcc32 Error] UPedido.pas(34): E2137 Method 'GetAsJson' not found in base class

  • [dcc32 Error] UPedido.pas(60): E2003 Undeclared identifier: 'RefreshArray'

  • Classe Gerada:

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
Copy link

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
Copy link

@MatheusLetra can you please provide me with the JSON?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants