Merge pull request #3328 from emqx/fix_json_encode_for40

Fix emqx_json encode return types error
This commit is contained in:
turtleDeng 2020-03-21 14:33:44 +08:00 committed by GitHub
commit 545ba905dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 1 deletions

View File

@ -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).