diff --git a/rebar.config b/rebar.config index 973f680..f9d71b3 100644 --- a/rebar.config +++ b/rebar.config @@ -1,7 +1,7 @@ {require_min_otp_vsn, "21"}. {deps, [ - {euneus, "~>2.3"}, + {euneus, "~>2.4"}, {json_polyfill, "0.1.4"} ]}. diff --git a/rebar.lock b/rebar.lock index e8e6afc..e9b6b6d 100644 --- a/rebar.lock +++ b/rebar.lock @@ -1,11 +1,11 @@ {"1.2.0", -[{<<"euneus">>,{pkg,<<"euneus">>,<<"2.3.0">>},0}, +[{<<"euneus">>,{pkg,<<"euneus">>,<<"2.4.0">>},0}, {<<"json_polyfill">>,{pkg,<<"json_polyfill">>,<<"0.1.4">>},0}]}. [ {pkg_hash,[ - {<<"euneus">>, <<"4F9B77EFD1A5C7DD9C3CA0AB0C51172035BC39BFF28B37AA9789C173D1DD397A">>}, + {<<"euneus">>, <<"E58178FB3B2C6FE139C863C4B347574E4C599BF1B9530ED3BAE7A10E2C7F870A">>}, {<<"json_polyfill">>, <<"ED9AD7A8CBDB8D1F1E59E22CDAE23A153A5BB93B5529AEBAEB189CA4B4C536C8">>}]}, {pkg_hash_ext,[ - {<<"euneus">>, <<"335E8A4D6A7F822E4FEA72CA1D3DD56A456F4E13427AF2C0B77B872584CF8048">>}, + {<<"euneus">>, <<"200EEFCE320314831AD79D77F03B109BC035E0A282B6B71FBCD3A7982804184D">>}, {<<"json_polyfill">>, <<"48C397EE2547FA459EDE01A30EC0E85717ABED3010867A63EEAAC5F203274303">>}]} ]. diff --git a/src/jsxrecord.erl b/src/jsxrecord.erl index 6ed1235..76f382a 100644 --- a/src/jsxrecord.erl +++ b/src/jsxrecord.erl @@ -94,8 +94,8 @@ encode_json(Term) -> codecs => [ timestamp, datetime ], nulls => [undefined, null], skip_values => [], - proplists => true, - encode_list => fun encode_list/2, + key_to_binary => fun key_to_binary/1, + proplists => {true, fun is_proplist/1}, encode_tuple => fun encode_tuple/2, encode_pid => fun encode_unknown/2, encode_port => fun encode_unknown/2, @@ -113,17 +113,17 @@ decode_json(B) -> }, euneus:decode(B, Options). -encode_list([{K, _} | _] = Proplist, Opts) when ?IS_PROPLIST_KEY(K) -> - Map = proplists:to_map(Proplist), - euneus_encoder:encode_map(Map, Opts); -encode_list(List, Opts) -> - case lists:all(fun is_atom/1, List) of - true -> - List1 = [ atom_to_binary(A, utf8) || A <- List ], - euneus_encoder:encode_list(List1, Opts); - false -> - euneus_encoder:encode_list(List, Opts) - end. +key_to_binary(Bin) when is_binary(Bin) -> + Bin; +key_to_binary(Atom) when is_atom(Atom) -> + atom_to_binary(Atom, utf8); +key_to_binary(Int) when is_integer(Int) -> + integer_to_binary(Int, 10). + +is_proplist([{K, _} | _]) when ?IS_PROPLIST_KEY(K) -> + true; +is_proplist(_List) -> + false. encode_tuple({struct, MochiJSON}, Opts) -> Map = mochijson_to_map(MochiJSON),