summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKenneth Lundin <kenneth@erlang.org>2021-04-01 12:03:01 +0200
committerKenneth Lundin <kenneth@erlang.org>2021-04-01 12:03:01 +0200
commit6b84252af93f3353ba438d679052565cdbcf646a (patch)
tree2b0a88edfc96349e99a86b24e78a880495268e4a
parent6a41828dd3a73b7b7705ac24fcfccfe2c7835f2a (diff)
downloaderlang-6b84252af93f3353ba438d679052565cdbcf646a.tar.gz
Change the internal representation of a sequence to a property list
instead of a map to maintain the order of the fields in the resulting JSON object. This is more friendly for debugging. ERIERL-607, OTP-17297
-rw-r--r--lib/asn1/src/asn1rtt_jer.erl20
1 files changed, 11 insertions, 9 deletions
diff --git a/lib/asn1/src/asn1rtt_jer.erl b/lib/asn1/src/asn1rtt_jer.erl
index 277686df02..80006e78a7 100644
--- a/lib/asn1/src/asn1rtt_jer.erl
+++ b/lib/asn1/src/asn1rtt_jer.erl
@@ -53,7 +53,7 @@ encode_jer({sequence_tab,Simple,Sname,Arity,CompInfos},Value)
encode_jer({sequence,Sname,Arity,CompInfos},Value)
when tuple_size(Value) == Arity+1 ->
[Sname|Clist] = tuple_to_list(Value),
- encode_jer_component(CompInfos,Clist,#{});
+ encode_jer_component(CompInfos,Clist,[]);
encode_jer(string,Str) when is_list(Str) ->
list_to_binary(Str);
encode_jer({string,_Prop},Str) when is_list(Str) ->
@@ -168,15 +168,17 @@ encode_jer_component_tab([{Name, Type, _OptOrDefault} | CompInfos], [Value | Res
encode_jer_component_tab([], _, _Simple, MapAcc) ->
MapAcc.
-encode_jer_component([{_Name, _Type, 'OPTIONAL'} | CompInfos], [asn1_NOVALUE | Rest], MapAcc) ->
- encode_jer_component(CompInfos, Rest, MapAcc);
-encode_jer_component([{_Name, _Type, {'DEFAULT',_}} | CompInfos], [asn1_DEFAULT | Rest], MapAcc) ->
- encode_jer_component(CompInfos, Rest, MapAcc);
-encode_jer_component([{Name, Type, _OptOrDefault} | CompInfos], [Value | Rest], MapAcc) ->
+encode_jer_component([{_Name, _Type, 'OPTIONAL'} | CompInfos], [asn1_NOVALUE | Rest], Acc) ->
+ encode_jer_component(CompInfos, Rest, Acc);
+encode_jer_component([{_Name, _Type, {'DEFAULT',_}} | CompInfos], [asn1_DEFAULT | Rest], Acc) ->
+ encode_jer_component(CompInfos, Rest, Acc);
+encode_jer_component([{Name, Type, _OptOrDefault} | CompInfos], [Value | Rest], Acc) ->
Enc = encode_jer(Type, Value),
- encode_jer_component(CompInfos, Rest, MapAcc#{Name => Enc});
-encode_jer_component([], _, MapAcc) ->
- MapAcc.
+ encode_jer_component(CompInfos, Rest, [{Name,Enc}|Acc]);
+encode_jer_component([], _, []) ->
+ #{}; % ensure that it is encoded as an empty object in JSON
+encode_jer_component([], _, Acc) ->
+ lists:reverse(Acc).
decode_jer(Module,InfoFunc,Val) ->
Info = Module:InfoFunc(),