Wrong decoding of nested map
I would like to encode a map having multiple values (primitive, date or empty map):
map[string]any{
"a": "abcd",
"b": 42,
"c": false,
"d": myDate,
"e": map[string]any{}, // <- always empty and not nil
"f": nil,
},
I use the following schema:
...
{
"name": "my_map",
"type": {
"type": "map",
"values": [
"string",
"int",
"long",
"float",
"double",
"boolean",
"null",
{
"type": "long",
"logicalType": "timestamp-millis"
},
{
"type": "map",
"values": "null" // <- can be any type since the map will always be {}
}
]
}
}
...
After go->avro->go conversion, I get the following map:
{
"a": {
"string": "abcd"
},
"b": {
"int": 42
},
"c": {
"boolean": false
},
"d": {
"long.timestamp-millis": "2024-02-06T10:38:03.033Z"
},
"e": null,
"f": null
}
Does anybody know why the library inserts the type as key ?
When I remove the nested map in schema, the map is decoded properly, except for e being nil, instead of empty map.
Your type is a map of union, and as stated in the README, and unions in the generic form decode to a map with the type as the only key. The any union type does not apply in this case because you are doing a generic decode. That is my assumption at any rate, as there is not enough here to actually tell, but it is what it looks like.
Assuming the question has been answered. If there still an issue, please reopen.