iskra / jsonx

JSONX is an Erlang library for efficient decode and encode JSON, written in C.
Other
91 stars 32 forks source link

Error in output. #16

Open egorovd opened 10 years ago

egorovd commented 10 years ago
-module(json_t).

-record(json_t, {
    name :: binary(),
    age = 0 :: pos_integer(),
    spouse :: #json_t{}
}).

-record(json_t2, {
  name :: binary(),
  age = 0 :: pos_integer(),
  spouse :: #json_t{}
}).

encoder1() ->
    jsonx:encoder([{json_t, record_info(fields, json_t)},
                             {json_t2, record_info(fields, json_t2)} ], 
                             [{ignore, [undefined]}]).

a() ->
  R = #json_t2{ name = <<"John">>, age = 32, spouse = [#json_t{}] },
  Encoder = encoder1(),
  Res = Encoder(R),
  io:format("~p ~n",[Res]).

RESULT:

<<"{\"name\": \"John\",\"age\": 32,\"spouse\": [{,\"age\": 0}]}">>

If first field in record == undefined.