add JSX_FORCE_MAPS flag for forcing decoding to maps
This commit is contained in:
parent
8e75e0f312
commit
cdd01c6eac
5 changed files with 30 additions and 8 deletions
|
@ -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
|
||||
|
|
14
README.md
14
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: [](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/
|
||||
|
|
8
mix.exs
8
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}]
|
||||
|
||||
|
|
|
@ -1,6 +1 @@
|
|||
{erl_opts, [
|
||||
% uncomment to always decode to maps
|
||||
% {d, maps_always},
|
||||
]}.
|
||||
|
||||
{edoc_opts, [{preprocess, true}]}.
|
||||
|
|
|
@ -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}).
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue