-
Notifications
You must be signed in to change notification settings - Fork 1
/
ser-des.py
51 lines (43 loc) · 1.11 KB
/
ser-des.py
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
from pykson import Pykson,JsonObject, IntegerField, StringField, DateField, ListField
import pickle
class Cliente(JsonObject):
nome = StringField()
sobre_nome = StringField()
idade = IntegerField()
data_nasc = DateField()
endereco = StringField()
bairro = StringField()
cidade = StringField()
estado = StringField()
pais = StringField()
profissao = StringField()
score = ListField(int)
tags = ListField(str)
teste = Cliente(
nome='Joazinho',
sobre_nome='da silva',
idade=12,
data_nasc='1980-01-01',
endereco='Rua ABC',
bairro='Aquele',
cidade='Porto Alegre',
estado='RS',
pais='brasil',
profissao='Estudante',
score=[10, 8, 9],
tags=['aluno', 'bom', 'aprovado'],
)
#Serialize
print('Serialize')
teste1 = Pykson().to_json(teste)
with open('data.json', 'wb') as fp:
pickle.dump(teste1, fp)
with open('data.json', 'rb') as fp:
data = pickle.load(fp)
print(data)
print(type(data))
print('===============================================')
#Deserialize
print('Deserialize')
teste = Pykson().from_json(data, Cliente)
print(teste)