mirror of
https://github.com/processone/ejabberd.git
synced 2024-12-22 17:28:25 +01:00
Add misc:json_encode_With_kv_lists and use it in matrix sign function
R27 json module doesn't recognize list of tuples as object specification, so this creates wrapper that offer this functionality.
This commit is contained in:
parent
8d4c1e3617
commit
a4fd756eae
11
src/misc.erl
11
src/misc.erl
@ -42,7 +42,7 @@
|
||||
is_mucsub_message/1, best_match/2, pmap/2, peach/2, format_exception/4,
|
||||
get_my_ipv4_address/0, get_my_ipv6_address/0, parse_ip_mask/1,
|
||||
crypto_hmac/3, crypto_hmac/4, uri_parse/1, uri_parse/2, uri_quote/1,
|
||||
json_encode/1, json_decode/1,
|
||||
json_encode/1, json_decode/1, json_encode_with_kv_lists/1,
|
||||
set_proc_label/1,
|
||||
match_ip_mask/3, format_hosts_list/1, format_cycle/1, delete_dir/1,
|
||||
semver_to_xxyy/1, logical_processors/0, get_mucsub_event_type/1]).
|
||||
@ -132,11 +132,20 @@ crypto_hmac(Type, Key, Data, MacL) -> crypto:macN(hmac, Type, Key, Data, MacL).
|
||||
-endif.
|
||||
|
||||
-ifdef(OTP_BELOW_27).
|
||||
json_encode_with_kv_lists(Term) ->
|
||||
jiffy:encode(Term).
|
||||
json_encode(Term) ->
|
||||
jiffy:encode(Term).
|
||||
json_decode(Bin) ->
|
||||
jiffy:decode(Bin, [return_maps]).
|
||||
-else.
|
||||
json_encode_with_kv_lists(Term) ->
|
||||
iolist_to_binary(json:encode(Term),
|
||||
fun([{_, _} | _] = Val, Encoder) ->
|
||||
json:encode_key_value_list(Val, Encoder);
|
||||
(Val, Encoder) ->
|
||||
json:encode_value(Val, Encoder)
|
||||
end).
|
||||
json_encode(Term) ->
|
||||
iolist_to_binary(json:encode(Term)).
|
||||
json_decode(Bin) ->
|
||||
|
@ -673,7 +673,7 @@ get_pruned_event_id(PrunedEvent) ->
|
||||
|
||||
encode_canonical_json(JSON) ->
|
||||
JSON2 = sort_json(JSON),
|
||||
misc:json_encode(JSON2).
|
||||
misc:json_encode_with_kv_lists(JSON2).
|
||||
|
||||
sort_json(#{} = Map) ->
|
||||
Map2 = maps:map(fun(_K, V) ->
|
||||
|
Loading…
Reference in New Issue
Block a user