Open egorovd opened 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.
RESULT:
<<"{\"name\": \"John\",\"age\": 32,\"spouse\": [{,\"age\": 0}]}">>
If first field in record == undefined.