File tree Expand file tree Collapse file tree 2 files changed +45
-1
lines changed Expand file tree Collapse file tree 2 files changed +45
-1
lines changed Original file line number Diff line number Diff line change @@ -183,6 +183,9 @@ func (decoder *fuzzyStringDecoder) Decode(ptr unsafe.Pointer, iter *jsoniter.Ite
183
183
* ((* string )(ptr )) = string (number )
184
184
case jsoniter .StringValue :
185
185
* ((* string )(ptr )) = iter .ReadString ()
186
+ case jsoniter .NilValue :
187
+ iter .Skip ()
188
+ * ((* string )(ptr )) = ""
186
189
default :
187
190
iter .ReportError ("fuzzyStringDecoder" , "not number or string" )
188
191
}
@@ -208,6 +211,9 @@ func (decoder *fuzzyIntegerDecoder) Decode(ptr unsafe.Pointer, iter *jsoniter.It
208
211
} else {
209
212
str = "0"
210
213
}
214
+ case jsoniter .NilValue :
215
+ iter .Skip ()
216
+ str = "0"
211
217
default :
212
218
iter .ReportError ("fuzzyIntegerDecoder" , "not number or string" )
213
219
}
@@ -244,6 +250,9 @@ func (decoder *fuzzyFloat32Decoder) Decode(ptr unsafe.Pointer, iter *jsoniter.It
244
250
} else {
245
251
* ((* float32 )(ptr )) = 0
246
252
}
253
+ case jsoniter .NilValue :
254
+ iter .Skip ()
255
+ * ((* float32 )(ptr )) = 0
247
256
default :
248
257
iter .ReportError ("fuzzyFloat32Decoder" , "not number or string" )
249
258
}
@@ -273,7 +282,10 @@ func (decoder *fuzzyFloat64Decoder) Decode(ptr unsafe.Pointer, iter *jsoniter.It
273
282
} else {
274
283
* ((* float64 )(ptr )) = 0
275
284
}
285
+ case jsoniter .NilValue :
286
+ iter .Skip ()
287
+ * ((* float64 )(ptr )) = 0
276
288
default :
277
- iter .ReportError ("fuzzyFloat32Decoder " , "not number or string" )
289
+ iter .ReportError ("fuzzyFloat64Decoder " , "not number or string" )
278
290
}
279
291
}
Original file line number Diff line number Diff line change @@ -357,3 +357,35 @@ func Test_bad_case(t *testing.T) {
357
357
should := require .New (t )
358
358
should .Nil (err )
359
359
}
360
+
361
+ func Test_null_to_string (t * testing.T ) {
362
+ should := require .New (t )
363
+ body := []byte (`null` )
364
+ var message string
365
+ err := jsoniter .Unmarshal (body , & message )
366
+ should .NoError (err )
367
+ }
368
+
369
+ func Test_null_to_int (t * testing.T ) {
370
+ should := require .New (t )
371
+ body := []byte (`null` )
372
+ var message int
373
+ err := jsoniter .Unmarshal (body , & message )
374
+ should .NoError (err )
375
+ }
376
+
377
+ func Test_null_to_float32 (t * testing.T ) {
378
+ should := require .New (t )
379
+ body := []byte (`null` )
380
+ var message float32
381
+ err := jsoniter .Unmarshal (body , & message )
382
+ should .NoError (err )
383
+ }
384
+
385
+ func Test_null_to_float64 (t * testing.T ) {
386
+ should := require .New (t )
387
+ body := []byte (`null` )
388
+ var message float64
389
+ err := jsoniter .Unmarshal (body , & message )
390
+ should .NoError (err )
391
+ }
You can’t perform that action at this time.
0 commit comments