Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions cmd/avrogo/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,11 @@ func canOmitUnionInfo(u typeInfo) bool {
// Check that either there's no union or the union is ["null", T]
// (the default union type for a pointer) and the Go type is also
// a pointer, meaning the avro package can infer that it's a
// pointer union.
return len(u.Union) == 0 || (len(u.Union) == 2 && u.Union[0].GoType == nullType && u.GoType[0] == '*')
// pointer union.
// If the union is ["null", map[string]T] then we can't omit the union
// Example: mapTest *map[string]interface{} `json:"mapTest"` will omit the union without this check for map
return len(u.Union) == 0 || (len(u.Union) == 2 && u.Union[0].GoType == nullType && u.GoType[0] == '*' && len(u.GoType) > 3 && u.GoType[:4] != "*map")

}

func writeUnionInfo(w io.Writer, info typeInfo) {
Expand Down