Skip to content

Commit

Permalink
Conditional compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
josevalim committed Nov 27, 2024
1 parent f299271 commit 8b7275f
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/elixir/src/elixir_json.erl
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,13 @@ list_loop([Elem | Rest], Encode) -> [$,, Encode(Elem, Encode) | list_loop(Rest,
encode_map(Map, Encode) when is_map(Map) ->
do_encode_map(Map, Encode).

-if(?OTP_RELEASE >= 26).
do_encode_map(Map, Encode) when is_function(Encode, 2) ->
encode_object([[$,, key(Key, Encode), $: | Encode(Value, Encode)] || Key := Value <- Map]).
-else.
do_encode_map(Map, Encode) when is_function(Encode, 2) ->
encode_object([[$,, key(Key, Encode), $: | Encode(Value, Encode)] || {Key, Value} <- maps:to_list(Map)]).
-endif.

-spec encode_map_checked(map(), encoder()) -> iodata().
encode_map_checked(Map, Encode) ->
Expand Down

0 comments on commit 8b7275f

Please sign in to comment.