File tree 3 files changed +27
-0
lines changed
3 files changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -204,10 +204,12 @@ func genMap(mapType *ast.MapType) {
204
204
}
205
205
206
206
func genStruct (structType * ast.StructType ) {
207
+ oldLines := lines
207
208
_l (" more := iter.ReadObjectHead()" )
208
209
_l (" for more {" )
209
210
_l (" field := iter.ReadObjectField()" )
210
211
_l (" switch {" )
212
+ isEmptyStruct := true
211
213
for _ , field := range structType .Fields .List {
212
214
fieldName := field .Names [0 ].Name
213
215
encodedFieldName := fieldName
@@ -230,10 +232,15 @@ func genStruct(structType *ast.StructType) {
230
232
if isNotExported {
231
233
continue
232
234
}
235
+ isEmptyStruct = false
233
236
ptr := fmt .Sprintf ("&(*out).%s" , fieldName )
234
237
_f (" case field == `%s`:" , encodedFieldName )
235
238
genDecodeStmt (field .Type , ptr )
236
239
}
240
+ if isEmptyStruct {
241
+ lines = oldLines
242
+ return
243
+ }
237
244
_l (" default:" )
238
245
_l (" iter.Skip()" )
239
246
_l (" }" )
Original file line number Diff line number Diff line change
1
+ package value_tests
2
+
3
+ //go:generate go run github.com/json-iterator/tinygo/gen
4
+ type EmptyStruct struct {
5
+ }
Original file line number Diff line number Diff line change
1
+ package value_tests
2
+
3
+ import jsoniter "github.com/json-iterator/tinygo"
4
+
5
+ func EmptyStruct_json_unmarshal (iter * jsoniter.Iterator , out * EmptyStruct ) {
6
+ }
7
+ type EmptyStruct_json struct {
8
+ }
9
+ func (json EmptyStruct_json ) Type () interface {} {
10
+ var val EmptyStruct
11
+ return & val
12
+ }
13
+ func (json EmptyStruct_json ) Unmarshal (iter * jsoniter.Iterator , val interface {}) {
14
+ EmptyStruct_json_unmarshal (iter , val .(* EmptyStruct ))
15
+ }
You can’t perform that action at this time.
0 commit comments