Skip to content
This repository has been archived by the owner on Jan 12, 2023. It is now read-only.

Commit

Permalink
Support typed root lists
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard Jonas committed Oct 4, 2017
1 parent a36503f commit 955826c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/ejson.erl
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,9 @@ from_json_modules(Binary, ModuleList) ->
from_json(Binary, Rules, Opts).

from_json_modules(Binary, ModuleList, Record) ->
Opts = json_rules(ModuleList),
from_json(Binary, Opts, Record).
Rules = json_rules(ModuleList),
Opts = json_opts(ModuleList),
from_json(Binary, Record, Rules, Opts).

from_json(Binary, Rules, Opts) ->
Decoded = jsx:decode(Binary),
Expand Down
18 changes: 18 additions & 0 deletions src/ejson_decode.erl
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,24 @@
%% information about the target type (__rec or so).
%% @end
%%-----------------------------------------------------------------------------
decode([H | _] = List, RecordName, Rules, Opts) when is_list(H) ->
R = lists:foldl(
fun(AttrList, Acc) when is_list(Acc) ->
case decode1(AttrList, RecordName, Rules, Opts) of
{error, _} = E ->
E;
Record ->
[Record | Acc]
end;
(_, {error, _} = E) ->
E
end, [], List),
case R of
_ when is_list(R) ->
lists:reverse(R);
_ ->
R
end;
decode(AttrList, RecordName, Rules, Opts) ->
case decode1(AttrList, RecordName, Rules, Opts) of
{error, _} = Error ->
Expand Down

0 comments on commit 955826c

Please sign in to comment.