From d4d838d4f4593dfab4d607036338d73cec108593 Mon Sep 17 00:00:00 2001 From: alisdair sullivan Date: Thu, 18 Dec 2014 15:58:19 -0800 Subject: [PATCH] always return maps if the macro `maps_always` is defined --- rebar.config | 2 ++ src/jsx_to_term.erl | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/rebar.config b/rebar.config index b2653a2..38858b5 100644 --- a/rebar.config +++ b/rebar.config @@ -1,4 +1,6 @@ {erl_opts, [ + % uncomment to always decode to maps + % {d, maps_always}, {platform_define, "R14|R15", 'no_binary_to_whatever'}, {platform_define, "^((?!R1[456]).)*$", 'maps_support'} ]}. \ No newline at end of file diff --git a/src/jsx_to_term.erl b/src/jsx_to_term.erl index d5db2c3..4ace068 100644 --- a/src/jsx_to_term.erl +++ b/src/jsx_to_term.erl @@ -69,9 +69,14 @@ -spec to_term(Source::binary(), Config::config()) -> json_value(). +-ifdef(maps_always). +to_term(Source, Config) when is_list(Config) -> + (jsx:decoder(?MODULE, [return_maps] ++ Config, jsx_config:extract_config(Config)))(Source). +-endif. +-ifndef(maps_always). to_term(Source, Config) when is_list(Config) -> (jsx:decoder(?MODULE, Config, jsx_config:extract_config(Config)))(Source). - +-endif. parse_config(Config) -> parse_config(Config, #config{}).