From 9e78adb70d098e42efc3cc4f216e2c53e59e0349 Mon Sep 17 00:00:00 2001 From: Nicholas Wiersma Date: Wed, 7 Aug 2024 14:37:42 +0200 Subject: [PATCH] fix: map record decodes in union case (#427) --- codec_record.go | 2 +- decoder_record_test.go | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/codec_record.go b/codec_record.go index 7cfdbef3..4a01b125 100644 --- a/codec_record.go +++ b/codec_record.go @@ -275,7 +275,7 @@ func decoderOfRecord(d *decoderContext, schema Schema, typ reflect2.Type) ValDec fields[i] = recordMapDecoderField{ name: field.Name(), - decoder: newEfaceDecoder(d, field.Type()), + decoder: decoderOfType(d, field.Type(), mapType.Elem()), } } diff --git a/decoder_record_test.go b/decoder_record_test.go index 0d1d23f4..69faf7c0 100644 --- a/decoder_record_test.go +++ b/decoder_record_test.go @@ -236,13 +236,14 @@ func TestDecoder_RecordEmbeddedIntStruct(t *testing.T) { func TestDecoder_RecordMap(t *testing.T) { defer ConfigTeardown() - data := []byte{0x36, 0x06, 0x66, 0x6f, 0x6f} + data := []byte{0x36, 0x06, 0x66, 0x6f, 0x6f, 0x02, 0x06, 0x66, 0x6f, 0x6f} schema := `{ "type": "record", "name": "test", "fields" : [ {"name": "a", "type": "long"}, - {"name": "b", "type": "string"} + {"name": "b", "type": "string"}, + {"name": "c", "type": ["null","string"]} ] }` dec, err := avro.NewDecoder(schema, bytes.NewReader(data)) @@ -252,7 +253,7 @@ func TestDecoder_RecordMap(t *testing.T) { err = dec.Decode(&got) require.NoError(t, err) - assert.Equal(t, map[string]any{"a": int64(27), "b": "foo"}, got) + assert.Equal(t, map[string]any{"a": int64(27), "b": "foo", "c": "foo"}, got) } func TestDecoder_RecordMapInvalidKey(t *testing.T) {