From cdd01c6eac1bf37d6c83bdba60a600946b9a032f Mon Sep 17 00:00:00 2001 From: alisdair sullivan Date: Thu, 8 Oct 2015 22:50:04 -0700 Subject: [PATCH] add JSX_FORCE_MAPS flag for forcing decoding to maps --- CHANGES.md | 5 +++++ README.md | 14 +++++++++++++- mix.exs | 8 +++++++- rebar.config | 5 ----- rebar.config.script | 6 +++++- 5 files changed, 30 insertions(+), 8 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 23f866b..a79db60 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,8 @@ +v2.8.0 + +* add `JSX_FORCE_MAPS` env var for forcing decoding to maps rather than + attempting to autodetect + v2.7.2 * fix an issue where tuples were assumed to be jsx ast and not checked diff --git a/README.md b/README.md index 44920c2..48baf11 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ an erlang application for consuming, producing and manipulating [json][json]. inspired by [yajl][yajl] -**jsx** is built via [rebar][rebar] and continuous integration testing provided courtesy [travis-ci][travis] +**jsx** is built via [rebar3][rebar3], [rebar][rebar] or [mix][mix] and continuous integration testing provided courtesy [travis-ci][travis] current status: [![Build Status](https://secure.travis-ci.org/talentdeficit/jsx.png?branch=develop)](http://travis-ci.org/talentdeficit/jsx) @@ -51,8 +51,12 @@ for the overview or [migrating from 1.x](#migrating) for the details #### to build the library and run tests #### ```bash +$ rebar3 compile +$ rebar3 eunit $ rebar compile $ rebar eunit +$ mix compile +$ mix eunit ``` #### to convert a utf8 binary containing a json string into an erlang term #### @@ -116,6 +120,12 @@ false }">> ``` +#### to compile **jsx** so that it always decodes json objects to maps #### + +```bash +$ JSX_FORCE_MAPS rebar3 compile +$ JSX_FORCE_MAPS mix compile +``` ## description ## @@ -720,7 +730,9 @@ jsx wouldn't be what it is without the contributions of [Paul J. Davis](https:// [json]: http://json.org [yajl]: http://lloyd.github.com/yajl [MIT]: http://www.opensource.org/licenses/mit-license.html +[rebar3]: https://rebar3.org [rebar]: https://github.com/rebar/rebar +[mix]: http://elixir-lang.org/getting-started/mix-otp/introduction-to-mix.html [meck]: https://github.com/eproxus/meck [rfc4627]: http://tools.ietf.org/html/rfc4627 [travis]: https://travis-ci.org/ diff --git a/mix.exs b/mix.exs index acc4152..b6e996a 100644 --- a/mix.exs +++ b/mix.exs @@ -14,7 +14,13 @@ use Mix.Project end defp opts(:dev), do: [d: :TEST] ++ opts(:prod) - defp opts(_), do: [d: :maps_support, d: :maps_always] + defp opts(_) do + force_maps = case System.get_env("JSX_FORCE_MAPS") do + nil -> [] + _ -> [d: :maps_always] + end + [d: :maps_support] ++ force_maps + end defp deps(_), do: [{:mixunit, "~> 0.9.2", only: :dev}] diff --git a/rebar.config b/rebar.config index 56e8e6a..51ac4c1 100644 --- a/rebar.config +++ b/rebar.config @@ -1,6 +1 @@ -{erl_opts, [ - % uncomment to always decode to maps - % {d, maps_always}, -]}. - {edoc_opts, [{preprocess, true}]}. diff --git a/rebar.config.script b/rebar.config.script index 4510155..5841b7d 100644 --- a/rebar.config.script +++ b/rebar.config.script @@ -3,9 +3,13 @@ Def0 = case erlang:is_builtin(erlang, binary_to_integer, 1) andalso true -> []; false -> [{d, no_binary_to_whatever}] end, -Defs = case erlang:is_builtin(erlang, is_map, 1) of +Def1 = case erlang:is_builtin(erlang, is_map, 1) of true -> [{d, maps_support}|Def0]; false -> Def0 end, +Defs = case os:getenv("JSX_FORCE_MAPS") of + false -> Def1; + _ -> [{d, maps_always}|Def1] + end, lists:keystore(erl_opts, 1, CONFIG, {erl_opts, proplists:get_value(erl_opts, CONFIG, []) ++ Defs}).