37
37
discard
38
38
39
39
SkipIfObject = object
40
+ alwaysSkipped {.skipped.}: int
41
+ serializeSkipped {.skipSerializing.}: int
40
42
text {.skipSerializeIf(isNone).}: Option[string ]
41
43
42
44
SerializeWithObject = object
43
45
date {.serializeWith(toTimestamp).}: DateTime
46
+
47
+ RenameObject = object
48
+ name {.renameSerialize("fullname").}: string
49
+
50
+ User = object
51
+ id: int
52
+
53
+ Pagination = object
54
+ limit: int64
55
+ offset: int64
56
+ total: int64
57
+
58
+ Users = object
59
+ users: seq [User]
60
+ pagination {.inlineKeys.}: Pagination
61
+
44
62
45
63
proc serialize[Serializer](self: ref int , serializer: var Serializer) =
46
64
serializer.serializeInt(self[])
@@ -54,6 +72,11 @@ makeSerializable(CaseObject)
54
72
makeSerializable(UntaggedCaseObject)
55
73
makeSerializable(SkipIfObject)
56
74
makeSerializable(SerializeWithObject)
75
+ makeSerializable(RenameObject)
76
+
77
+ makeSerializable(User)
78
+ makeSerializable(Pagination)
79
+ makeSerializable(Users)
57
80
58
81
suite "makeSerializable":
59
82
test "simple":
@@ -98,7 +121,7 @@ suite "makeSerializable":
98
121
StructEnd()
99
122
]
100
123
101
- test " case object " :
124
+ test " case" :
102
125
serTokens CaseObject(kind: true , yes: " yes" ), [
103
126
Struct(" CaseObject" ),
104
127
String(" kind" ),
@@ -115,7 +138,7 @@ suite "makeSerializable":
115
138
StructEnd()
116
139
]
117
140
118
- test " untagged case object " :
141
+ test " untagged case" :
119
142
serTokens UntaggedCaseObject(kind: true , yes: " yes" ), [
120
143
Struct(" UntaggedCaseObject" ),
121
144
String(" yes" ),
@@ -128,7 +151,7 @@ suite "makeSerializable":
128
151
StructEnd()
129
152
]
130
153
131
- test " object with skipSerializeIf" :
154
+ test " skipSerializeIf" :
132
155
serTokens SkipIfObject(text: some " text" ), [
133
156
Struct(" SkipIfObject" ),
134
157
String(" text" ),
@@ -141,11 +164,35 @@ suite "makeSerializable":
141
164
StructEnd()
142
165
]
143
166
144
- test " object with serializeWith" :
167
+ test " serializeWith" :
145
168
let date = now()
146
169
serTokens SerializeWithObject(date: date), [
147
170
Struct(" SerializeWithObject" ),
148
171
String(" date" ),
149
172
Integer(int (date.toTime.toUnix)),
150
173
StructEnd()
151
174
]
175
+
176
+ test " renameSerialize" :
177
+ serTokens RenameObject(name: " Name" ), [
178
+ Struct(" RenameObject" ),
179
+ String(" fullname" ),
180
+ String(" Name" ),
181
+ StructEnd()
182
+ ]
183
+
184
+ test " inlineKeys" :
185
+ serTokens Users(), [
186
+ Struct(" Users" ),
187
+ String(" users" ),
188
+ Seq(some 0 ),
189
+ SeqEnd(),
190
+ String(" limit" ),
191
+ Integer(0 ),
192
+ String(" offset" ),
193
+ Integer(0 ),
194
+ String(" total" ),
195
+ Integer(0 ),
196
+ StructEnd()
197
+ ]
198
+
0 commit comments