The Chicago Boss tutorial
http://www.chicagoboss.org/tutorial.pdf
gives an example of a BossRecord automatically being converted to JSON in a controller response to a GET like this:
pull('GET', [LastTimestamp]) ->
{ok, Timestamp, Greetings} = boss_mq:pull("new-greetings", list_to_integer(LastTimestamp)),
{json, [{timestamp, Timestamp}, {greetings, Greetings}]}.
However, this code doesn't work. boss_json will not convert "Greetings" record it gets from the boss_mq:pull, and gives me an unhandled error. I'm having a hard time figuring out what it wants.
16:50:45.634 [error] Unhandled Error: error:function_clause.
Stacktrace: [{boss_json,json_data1,[[{greeting,"greeting-77","zz"}],[],[]],
[{file,"src/boss/boss_json.erl"},{line,31}]},
{boss_json,json_data1,3,[{file,"src/boss/boss_json.erl"},{line,42}]},
{boss_json,encode,2,[{file,"src/boss/boss_json.erl"},{line,16}]},
{boss_web_controller_render,process_action_result,4,[{file,"src/boss/boss_web_controller_render.erl"},{line,171}]},
{boss_web_controller,execute_action_inner,9,[{file,"src/boss/boss_web_controller.erl"},{line,337}]},
{boss_web_controller_handle_request,process_dynamic_request,4,[{file,"src/boss/boss_web_controller_handle_request.erl"},{line,242}]},
{boss_web_controller_handle_request,process_request,4,[{file,"src/boss/boss_web_controller_handle_request.erl"},{line,228}]},
{boss_web_controller_handle_request,set_timer,7,[{file,"src/boss/boss_web_controller_handle_request.erl"},{line,148}]}]
16:50:45.636 [info] POST /greeting/create [cbmonitor] 302 0ms
Any ideas why the tutorial example (written several years ago) no longer works in the current version of Chicago Boss?
This isn't actually an answer, but it is too long for comment. I run the example code from chicagoboss_tutorial and it works for me. You might try cloning this repository and checking out, what differs.
I also run
dbg
during execution.and it gave me following output:
Second argument of
boss_json:encode/2
andboss_json:json_data1
isModelList
and for some reason, you have empty model list. As I said before - try to compare your code with the code from repository.