@@ -416,6 +416,11 @@ func TestRecordSchema_ValidatesDefault(t *testing.T) {
416
416
schema : `{"type":"record", "name":"test", "namespace": "org.hamba.avro", "fields":[{"name": "a", "type": {"type":"record", "name": "test2", "fields":[{"name": "b", "type": "int"},{"name": "c", "type": "int", "default": 1}]}, "default": {"b": 1}}]}` ,
417
417
wantErr : assert .NoError ,
418
418
},
419
+ {
420
+ name : "Record With Nullable Field" ,
421
+ schema : `{"type":"record", "name":"test", "namespace": "org.hamba.avro", "fields":[{"name": "a", "type": {"type":"record", "name": "test2", "fields":[{"name": "b", "type": "int"},{"name": "c", "type": ["null","int"]}]}, "default": {"b": 1, "c": null}}]}` ,
422
+ wantErr : assert .NoError ,
423
+ },
419
424
{
420
425
name : "Record Not Map" ,
421
426
schema : `{"type":"record", "name":"test", "namespace": "org.hamba.avro", "fields":[{"name": "a", "type": {"type":"record", "name": "test2", "fields":[{"name": "b", "type": "int"},{"name": "c", "type": "int", "default": 1}]}, "default": "test"}]}` ,
@@ -438,9 +443,19 @@ func TestRecordSchema_ValidatesDefault(t *testing.T) {
438
443
t .Run (test .name , func (t * testing.T ) {
439
444
t .Parallel ()
440
445
441
- _ , err := avro .ParseWithCache (test .schema , "" , & avro.SchemaCache {})
446
+ schema , err := avro .ParseWithCache (test .schema , "" , & avro.SchemaCache {})
442
447
443
448
test .wantErr (t , err )
449
+ if err != nil {
450
+ return
451
+ }
452
+
453
+ // Ensure MarshalJSON Generate the same schema as it considers default values
454
+ b , err := schema .(* avro.RecordSchema ).MarshalJSON ()
455
+ assert .NoError (t , err )
456
+ schema2 , err := avro .ParseWithCache (string (b ), "" , & avro.SchemaCache {})
457
+ assert .NoError (t , err )
458
+ assert .Equal (t , schema , schema2 )
444
459
})
445
460
}
446
461
}
0 commit comments