Skip to content

Commit

Permalink
fix: map record decodes in union case (#427)
Browse files Browse the repository at this point in the history
  • Loading branch information
nrwiersma authored Aug 7, 2024
1 parent 4aff30f commit 9e78adb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion codec_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
}
}

Expand Down
7 changes: 4 additions & 3 deletions decoder_record_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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) {
Expand Down

0 comments on commit 9e78adb

Please sign in to comment.