Merge pull request #3328 from emqx/fix_json_encode_for40
Fix emqx_json encode return types error
This commit is contained in:
commit
545ba905dc
|
@ -55,7 +55,7 @@ encode(Term) ->
|
|||
|
||||
-spec(encode(json_term(), encode_options()) -> json_text()).
|
||||
encode(Term, Opts) ->
|
||||
jiffy:encode(to_ejson(Term), Opts).
|
||||
to_binary(jiffy:encode(to_ejson(Term), Opts)).
|
||||
|
||||
-spec(safe_encode(json_term())
|
||||
-> {ok, json_text()} | {error, Reason :: term()}).
|
||||
|
@ -118,3 +118,7 @@ from_ejson({L}) ->
|
|||
[{Name, from_ejson(Value)} || {Name, Value} <- L];
|
||||
from_ejson(T) -> T.
|
||||
|
||||
to_binary(B) when is_binary(B) -> B;
|
||||
to_binary(L) when is_list(L) ->
|
||||
iolist_to_binary(L).
|
||||
|
||||
|
|
Loading…
Reference in New Issue