[ 
https://issues.apache.org/jira/browse/THRIFT-1321?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13107614#comment-13107614
 ] 

Anthony Molinaro commented on THRIFT-1321:
------------------------------------------

Okay, I see what the issue is here.  You are using dict:append/3 which turns an 
entry in the dictionary into a list of entries.  This doesn't actually work 
with thrift (or it probably does in some odd way).  Instead you should be using 
dict:store/3 or dict:from_list/1 when creating the maps.  See if I were to make 
the change you are suggesting it would actually break serialization completely 
for the normal cases where you are creating a map.  Using append you are not
creating a map (unless you are creating a map<string,list> or something like 
that at which point I think it might make sense.

Using your first example you should be doing something like
{noformat}
Dict = dict:new(),
Dict2 = dict:store("key1", "value1", Dict),
Dict3 = dict:store("key2", [1,2,3], Dict2),
Dict4 = dict:store("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">>
{noformat}

> 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
>
>
> dict:fold/3 always return ValData as a list and therefore breaks the pattern 
> matching (guards).
> {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

        

Reply via email to