Map serialization is broken in the Erlang library
-------------------------------------------------
Key: THRIFT-1321
URL: https://issues.apache.org/jira/browse/THRIFT-1321
Project: Thrift
Issue Type: Bug
Components: Erlang - Library
Affects Versions: 0.7
Reporter: Louis-Philippe Gauthier
Attachments: bug.diff
{quote}
diff --git a/lib/erl/src/thrift_protocol.erl b/lib/erl/src/thrift_protocol.erl
index 193b07a..3a97a86 100644
--- a/lib/erl/src/thrift_protocol.erl
+++ b/lib/erl/src/thrift_protocol.erl
@@ -358,7 +358,7 @@ write(Proto0, {{map, KeyType, ValType}, Data}) ->
vtype = term_to_typeid(ValType),
size = dict:size(Data)
}),
- Proto2 = dict:fold(fun(KeyData, ValData, ProtoS0) ->
+ Proto2 = dict:fold(fun(KeyData, [ValData], ProtoS0) ->
{ProtoS1, ok} = write(ProtoS0, {KeyType,
KeyData}),
{ProtoS2, ok} = write(ProtoS1, {ValType,
ValData}),
ProtoS2
{quote}
dict:fold/3 always return ValData as a list and therefore breaks the pattern
matching.
{quote}
Dict = dict:new(),
Dict2 = dict:append("key1", "value1", Dict),
Dict3 = dict:append("key2", [1,2,3], Dict2),
Dict4 = dict:append("key3", <<"value3">>, Dict3),
dict:fold(fun(Key, Value, AccIn) -> io:format("~p : ~p~n", [Key, Value]) end,
[], Dict4).
"key1" : ["value1"]
"key2" : [[1,2,3]]
"key3" : [<<"value3">>]
{quote}
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira