add JSX_FORCE_MAPS flag for forcing decoding to maps

This commit is contained in:
alisdair sullivan 2015-10-08 22:50:04 -07:00
parent 8e75e0f312
commit cdd01c6eac
5 changed files with 30 additions and 8 deletions

View file

@ -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 v2.7.2
* fix an issue where tuples were assumed to be jsx ast and not checked * fix an issue where tuples were assumed to be jsx ast and not checked

View file

@ -4,7 +4,7 @@
an erlang application for consuming, producing and manipulating [json][json]. an erlang application for consuming, producing and manipulating [json][json].
inspired by [yajl][yajl] 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) 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 #### #### to build the library and run tests ####
```bash ```bash
$ rebar3 compile
$ rebar3 eunit
$ rebar compile $ rebar compile
$ rebar eunit $ rebar eunit
$ mix compile
$ mix eunit
``` ```
#### to convert a utf8 binary containing a json string into an erlang term #### #### 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 ## ## description ##
@ -720,7 +730,9 @@ jsx wouldn't be what it is without the contributions of [Paul J. Davis](https://
[json]: http://json.org [json]: http://json.org
[yajl]: http://lloyd.github.com/yajl [yajl]: http://lloyd.github.com/yajl
[MIT]: http://www.opensource.org/licenses/mit-license.html [MIT]: http://www.opensource.org/licenses/mit-license.html
[rebar3]: https://rebar3.org
[rebar]: https://github.com/rebar/rebar [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 [meck]: https://github.com/eproxus/meck
[rfc4627]: http://tools.ietf.org/html/rfc4627 [rfc4627]: http://tools.ietf.org/html/rfc4627
[travis]: https://travis-ci.org/ [travis]: https://travis-ci.org/

View file

@ -14,7 +14,13 @@ use Mix.Project
end end
defp opts(:dev), do: [d: :TEST] ++ opts(:prod) 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}] defp deps(_), do: [{:mixunit, "~> 0.9.2", only: :dev}]

View file

@ -1,6 +1 @@
{erl_opts, [
% uncomment to always decode to maps
% {d, maps_always},
]}.
{edoc_opts, [{preprocess, true}]}. {edoc_opts, [{preprocess, true}]}.

View file

@ -3,9 +3,13 @@ Def0 = case erlang:is_builtin(erlang, binary_to_integer, 1) andalso
true -> []; true -> [];
false -> [{d, no_binary_to_whatever}] false -> [{d, no_binary_to_whatever}]
end, 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]; true -> [{d, maps_support}|Def0];
false -> Def0 false -> Def0
end, end,
Defs = case os:getenv("JSX_FORCE_MAPS") of
false -> Def1;
_ -> [{d, maps_always}|Def1]
end,
lists:keystore(erl_opts, 1, CONFIG, lists:keystore(erl_opts, 1, CONFIG,
{erl_opts, proplists:get_value(erl_opts, CONFIG, []) ++ Defs}). {erl_opts, proplists:get_value(erl_opts, CONFIG, []) ++ Defs}).