-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathPessoa.pas
140 lines (112 loc) · 2.99 KB
/
Pessoa.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
unit Pessoa;
interface
uses
Generics.Collections,
Rest.Json;
type
TContatosDTO = class
private
FCodigo: Integer;
FEmail: string;
FNome: string;
FTelefone: string;
public
property Codigo: Integer read FCodigo write FCodigo;
property Email: string read FEmail write FEmail;
property Nome: string read FNome write FNome;
property Telefone: string read FTelefone write FTelefone;
end;
TEnderecoDTO = class
private
FBairro: string;
FCep: string;
FCidade: string;
FEstado: string;
FLogradouro: string;
FNumero: string;
public
property Bairro: string read FBairro write FBairro;
property Cep: string read FCep write FCep;
property Cidade: string read FCidade write FCidade;
property Estado: string read FEstado write FEstado;
property Logradouro: string read FLogradouro write FLogradouro;
property Numero: string read FNumero write FNumero;
end;
TPessoaDTO = class
private
FAtivo: Boolean;
FCodigo: Integer;
FContatos: TArray<TContatosDTO>;
FEndereco: TEnderecoDTO;
FNome: string;
public
property Ativo: Boolean read FAtivo write FAtivo;
property Codigo: Integer read FCodigo write FCodigo;
property Contatos: TArray<TContatosDTO> read FContatos write FContatos;
property Endereco: TEnderecoDTO read FEndereco write FEndereco;
property Nome: string read FNome write FNome;
constructor Create;
destructor Destroy; override;
class function FromJsonString(const AValue: string): TPessoaDTO; static;
function ToJsonString: string;
end;
TContent = class
private
FContent: TArray<TPessoaDTO>;
public
class function FromJsonString(const AValue: string): TContent; static;
function ToJsonString: string;
class function ToJsonList(const AVAlue: string): TList<TPessoaDTO>;
property Content: TArray<TPessoaDTO> read FContent write FContent;
destructor Destroy; override;
end;
implementation
uses
System.JSON;
{ TPessoaDTO }
constructor TPessoaDTO.Create;
begin
inherited;
FEndereco := TEnderecoDTO.Create;
end;
destructor TPessoaDTO.Destroy;
var
Element: TContatosDTO;
begin
FEndereco.Free;
for Element in FContatos do
Element.Free;
inherited;
end;
class function TPessoaDTO.FromJsonString(const AValue: string): TPessoaDTO;
begin
Result := TJson.JsonToObject<TPessoaDTO>(AValue);
end;
function TPessoaDTO.ToJsonString: string;
begin
Result := TJson.ObjectToJsonString(self);
end;
{ TRootDTO }
destructor TContent.Destroy;
var
Element: TObject;
begin
for Element in FContent do
Element.Free;
inherited;
end;
class function TContent.ToJsonList(const AVAlue: string): TList<TPessoaDTO>;
var
Return: TJSONArray;
begin
Return := TJSONObject.ParseJSONValue(AVAlue) as TJSONArray;
end;
class function TContent.FromJsonString(const AValue: string): TContent;
begin
Result := TJson.JsonToObject<TContent>(AValue);
end;
function TContent.ToJsonString: string;
begin
Result := TJson.ObjectToJsonString(self);
end;
end.