芝加哥的json编码老板教程不起作用

时间:2014-12-05 00:56:12

标签: json erlang chicagoboss

芝加哥老板教程

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

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

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

但是,这段代码不起作用。 boss_json不会转换#34; Greetings"记录它来自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?

1 个答案:

答案 0 :(得分: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/2boss_json:json_data1的第二个参数是ModelList,由于某种原因,您有空模型列表。正如我之前所说 - 尝试将您的代码与存储库中的代码进行比较。