Skip to content

Commit

Permalink
Merge pull request #145 from ssepml/jiffy_binary
Browse files Browse the repository at this point in the history
Ensure 'jiffy:encode/1' returns a binary
  • Loading branch information
potatosalad authored Dec 7, 2023
2 parents b4df4f2 + 173dcc4 commit c53977d
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/json/jose_json_jiffy.erl
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ decode(Binary) ->
jiffy:decode(Binary, [return_maps]).

encode(Map) when is_map(Map) ->
jiffy:encode(sort(Map));
ensure_binary(jiffy:encode(sort(Map)));
encode(List) when is_list(List) ->
jiffy:encode(sort(List));
ensure_binary(jiffy:encode(sort(List)));
encode(Term) ->
jiffy:encode(Term).
ensure_binary(jiffy:encode(Term)).

%%%-------------------------------------------------------------------
%%% Internal functions
Expand All @@ -40,3 +40,11 @@ sort(List) when is_list(List) ->
[sort(Term) || Term <- List];
sort(Term) ->
Term.

%% @private
%% NOTE: jiffy may return an iolist instead of a binary when encoding
%% big objects.
ensure_binary(List) when is_list(List) ->
iolist_to_binary(List);
ensure_binary(Binary) ->
Binary.

0 comments on commit c53977d

Please sign in to comment.