Skip to content

Commit

Permalink
Fix issue with encoding maps (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
Johnabell authored and cottinisimone committed Sep 5, 2024
1 parent e578093 commit 49be50f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/avrogen/code_generator.ex
Original file line number Diff line number Diff line change
Expand Up @@ -877,7 +877,7 @@ defmodule Avrogen.CodeGenerator do
raise "Error does not yet support maps with values of type #{type}"
end

~s'#{name}: Enum.into(#{name}, %{}, fn k, v -> {k, #{type_conversion}} end)'
~s'#{name}: Enum.into(#{name}, %{}, fn {k, v} -> {k, #{type_conversion}} end)'
end

def from_avro_map_body_field(%{"name" => name, "type" => union}, global) when is_list(union) do
Expand Down Expand Up @@ -1095,7 +1095,7 @@ defmodule Avrogen.CodeGenerator do
raise "Error does not yet support maps with values of type #{type}"
end

~s'"#{name}" => Enum.into(r.#{name}, %{}, fn k, v -> {k, #{type_conversion}} end)'
~s'"#{name}" => Enum.into(r.#{name}, %{}, fn {k, v} -> {k, #{type_conversion}} end)'
end

def to_avro_map_field(%{"name" => name, "type" => type}, global) when is_binary(type) do
Expand Down
4 changes: 2 additions & 2 deletions test/code_generator_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ defmodule Avrogen.CodeGenerator.Test do
}
}

assert ~s'"premium_breakdown" => Enum.into(r.premium_breakdown, %{}, fn k, v -> {k, Decimal.to_string(v)} end)' ==
assert ~s'"premium_breakdown" => Enum.into(r.premium_breakdown, %{}, fn {k, v} -> {k, Decimal.to_string(v)} end)' ==
CodeGenerator.to_avro_map_field(map_type, %{})
end
end
Expand All @@ -393,7 +393,7 @@ defmodule Avrogen.CodeGenerator.Test do
}
}

assert ~s'premium_breakdown: Enum.into(premium_breakdown, %{}, fn k, v -> {k, Decimal.new(v)} end)' ==
assert ~s'premium_breakdown: Enum.into(premium_breakdown, %{}, fn {k, v} -> {k, Decimal.new(v)} end)' ==
CodeGenerator.from_avro_map_body_field(map_type, %{})
end
end
Expand Down

0 comments on commit 49be50f

Please sign in to comment.