0

芝加哥老板教程

http://www.chicagoboss.org/tutorial.pdf

给出了一个 BossRecord 的示例,该示例在控制器对 GET 的响应中自动转换为 JSON,如下所示:

pull('GET', [LastTimestamp]) ->
    {ok, Timestamp, Greetings} = boss_mq:pull("new-greetings", list_to_integer(LastTimestamp)),
    {json, [{timestamp, Timestamp}, {greetings, Greetings}]}.

但是,此代码不起作用。boss_json 不会转换从 boss_mq:pull 获得的“问候”记录,并给我一个未处理的错误。我很难弄清楚它想要什么。

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

任何想法为什么教程示例(几年前编写)不再适用于当前版本的 Chicago Boss?

4

1 回答 1

1

这实际上不是一个答案,但评论太长了。我运行来自chicagoboss_tutorial的示例代码,它对我有用。您可以尝试克隆此存储库并检查,有什么不同。

我也在执行dbg期间运行。

dbg:tracer().
dbg:tpl(boss_json, '_', []).
dbg:p(all, c).

它给了我以下输出:

(<0.195.0>) call boss_json:encode([{timestamp,1417745752505174},{greetings,
[{greeting,"greeting-4","asdf"}]}],["greeting"])
(<0.195.0>) call boss_json:json_data1([{timestamp,1417745752505174},{greetings,[{greeting,"greeting-4","asdf"}]}],["greeting"],[])
(<0.195.0>) call boss_json:json_data1([{greetings,[{greeting,"greeting-4","asdf"}]}],["greeting"],[{timestamp,1417745752505174}])
(<0.195.0>) call boss_json:json_data1([],["greeting"],[{greetings,[{struct,[{id,<<"greeting-4">>},{greeting_text,<<"asdf">>}]}]},

boss_json:encode/2and的第二个参数boss_json:json_data1ModelList,由于某种原因,您有空的模型列表。正如我之前所说 - 尝试将您的代码与存储库中的代码进行比较。

于 2014-12-05T02:27:43.467 回答