Skip to content

Instantly share code, notes, and snippets.

@jdunphy
Created August 16, 2010 23:08
Show Gist options
  • Select an option

  • Save jdunphy/527932 to your computer and use it in GitHub Desktop.

Select an option

Save jdunphy/527932 to your computer and use it in GitHub Desktop.
diff --git a/lib/erlang/apps/beehive/src/bh_rest/rest_server.erl b/lib/erlang/apps/beehive/src/bh_rest/rest_server.erl
index e767a73..df26bfd 100644
--- a/lib/erlang/apps/beehive/src/bh_rest/rest_server.erl
+++ b/lib/erlang/apps/beehive/src/bh_rest/rest_server.erl
@@ -217,17 +217,24 @@ generalize_request_path(Path) ->
atomize_keys(Data) ->
+ erlang:display(Data),
lists:flatten(lists:map( fun({K,V}) -> atomize_kv(K,V) end, Data)).
atomize_kv(Key, []) ->
- case mochijson2:decode(Key) of
- {struct, List} when is_list(List) ->
- lists:map(fun({K,V}) -> atomize_kv(misc_utils:to_atom(K),misc_utils:to_list(V)) end, List);
- {BinKey, BinVal} ->
- Key = misc_utils:to_atom(BinKey),
- Val = misc_utils:to_list(BinVal),
- {Key, Val}
- end;
+ try mochijson2:decode(Key) of
+ {struct, List} when is_list(List) ->
+ lists:map(fun({K,V}) ->
+ atomize_kv(misc_utils:to_atom(K),
+ misc_utils:to_list(V)) end, List);
+ {BinKey, BinVal} ->
+ K = misc_utils:to_atom(BinKey),
+ Val = misc_utils:to_list(BinVal),
+ {K, Val};
+ catch
+ error:_Why -> {Key, []}
+ end;
+atomize_kv(Key, Value) when is_binary(Key) ->
+ atomize_kv(binary_to_list(Key), Value);
atomize_kv(Key, Value) when is_list(Key) -> atomize_kv(list_to_atom(Key), Value);
atomize_kv(Key, Value) when is_atom(Key) -> {Key, Value}.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment