I was able to use jsonx by adding it to the list of dependencies in
rebar.config and then replacing the 4 uses of mochijson2:encode in
src/boss/boss_json.erl
It seems to work, I'm not sure if I have missed anything, but everything
seems to have worked.
I also got jsone to work by:
Editing ChicaagoBoss/rebar.config
1. add, at the end of the maintained by others section, the following
dependency
{jsone, ".*", {git, "git://github.com/sile/jsone.git", {tag,
"v0.3.3-hipe"}}}
Editing ChicagoBoss/src/boss/boss_json
1. replace mochijson2:encode with jsone:encode
2. json_data1([], _, Acc) ->
{struct, lists:reverse(Acc)}; <- make this line {lists:reverse(Acc)};
Editing
ChicagoBoss/src/boss/model_manager_adapters/boss_model_manager_boss_db.erl
1. the final clause of to_json(Object) function changes from
{struct, Data}. to
{Data}.
On Wednesday, August 5, 2015 at 7:35:25 PM UTC-4, Evgeny M wrote:
>
> Jiffy does not work with tuples, and bossdb models are just tuples
>
> You need to put your model in a list and then put the list in another tuple
>
> jiffy:encode({[Model]})
>
>
> or something like this.
>
>
>
> четверг, 6 августа 2015 г., 0:10:59 UTC+3 пользователь jim rosenblum
> написал:
>>
>> For performance reasons I want to replace the use of mochijson2 with
>> jiffy. My CB webserver returns a large number (like 3000) models which have
>> to be encoded into json (the web controller returns {json, proplist})
>>
>> in boss_json.erl I replaced the calls to mochijson2:encode with
>> jiffy:encode
>>
>> encode([First|_] = Data, ModelList) ->
>> case boss_model_manager:is_model_instance(First, ModelList) of
>> true ->
>> %mochijson2:encode(lists:map(fun
>> boss_model_manager:to_json/1, Data));
>> jiffy:encode(lists:map(fun boss_model_manager:to_json/1,
>> Data)Sto_json);
>> false ->
>> %mochijson2:encode(json_data1(Data, ModelList, []))
>> jiffy:encode(json_data1(Data, ModelList, []))
>> end;
>>
>> encode([],_) ->
>> "";
>>
>> encode(Data, ModelList) ->
>> case boss_model_manager:is_model_instance (Data, ModelList) of
>> true ->
>> %mochijson2:encode(boss_model_manager:to_json(Data));
>> jiffy:encode(boss_model_manager:to_json(Data));
>> false ->
>> %mochijson2:encode(json_data1(Data, ModelList, []))
>> jiffy:encode(json_data1(Data, ModelList, []))
>> end.
>>
>>
>> When I then exercise CB, I receive the following error
>>
>>
>> [error] Unhandled Error: throw:{error,
>> {invalid_ejson,
>> {struct,
>> [{customers,
>> [{struct,
>> [{id,<<"customer-1">>},
>> {cust_id,<<"CUSTOMER1">>},
>> {description,<<"cust1">>},
>> {status,<<"green">>},
>> {status_time,<<"2015-08-05T16:47:33Z">>},
>> {status_time_desc,
>> <<"2015-08-05 16:47:33.570437">>}]}]},
>> {facilityCount,
>> [{struct,
>> [{count,0},
>> {monitored,0},
>> {green,0},
>> {yellow,0},
>> {red,0},
>> {paused,0}]}]}]}}} Stacktrace:
>> [{jiffy,encode,2,[{file,"src/jiffy.erl"},{line,93}]},{boss_web_controller_render,process_action_result,4,[{file,"src/boss/boss_web_controller_render.erl"},{line,178}]},{boss_web_controller,execute_action_inner,9,[{file,"src/boss/boss_web_controller.erl"},{line,290}]},{boss_web_controller_handle_request,process_dynamic_request,5,[{file,"src/boss/boss_web_controller_handle_request.erl"},{line,254}]},{boss_web_controller_handle_request,process_request,5,[{file,"src/boss/boss_web_controller_handle_request.erl"},{line,240}]},{boss_web_controller_handle_request,set_timer,8,[{file,"src/boss/boss_web_controller_handle_request.erl"},{line,160}]},{boss_web_controller_handle_request,build_dynamic_response,5,[{file,"src/boss/boss_web_controller_handle_request.erl"},{line,129}]},{boss_web_controller_handle_request,handle_request,4,[{file,"src/boss/boss_web_controller_handle_request.erl"},{line,26}]}]
>>
>>
>> Is anyone fluent enough in the differences between jiffy and mochijson2
>> to help me understand what I need to do?
>>
>
--
You received this message because you are subscribed to the Google Groups
"ChicagoBoss" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
Visit this group at http://groups.google.com/group/chicagoboss.
To view this discussion on the web visit
https://groups.google.com/d/msgid/chicagoboss/770fd5e7-6e20-4e1e-a02b-dd897e9e78d5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.