Serializer for Dancer2
Hi, I’ve been using serializer: "JSON" in my config.yml with no issues in Dancer2. Today I updated Dancer2 to the latest and now the pages come out blank. If I comment out the serializer line, things seem to return to normal (i.e. the pages render) - but my AJAX requests break. I’m not sure exactly what the last version of Dancer2 I was using. I also tested with the out of box app: dancer2 -a MyApp && cd MyApp plackup ./bin/app.pl -p 5000 -I lib If I add the serializer line to the config.yml it breaks (i.e. nothing page), otherwise it works. The error in the log file is (from my app): [project::WebApp:85745] core @2014-12-20 15:14:16> Failed to serialize the request: hash- or arrayref expected (not a simple scalar, use allow_nonref to allow this) at /perf/perl/lib/perl5/JSON.pm line 154. in (eval 754) l. 2 Regards, Matt
On 2014-12-20 05:44, Matthew Mallard wrote:
I’ve been using serializer: "JSON" in my config.yml with no issues in Dancer2. Today I updated Dancer2 to the latest and now the pages come out blank. If I comment out the serializer line, things seem to return to normal (i.e. the pages render) - but my AJAX requests break.
I *think* there were some recent changes that altered the conditions that serialisation occurs (I've been meaning to look at this in more detail for my own project, but haven't had a chance). Previously if you were using an auto-serialiser and returned a ref, then an attempt was made to serialise regardless of the request. Now serialisation will only take place if the request headers dictate such a response is appropriate. I stand by to be corrected on any of the above!
[project::WebApp:85745] core @2014-12-20 15:14:16> Failed to serialize the request: hash- or arrayref expected (not a simple scalar, use allow_nonref to allow this) at /perf/perl/lib/perl5/JSON.pm line 154. in (eval 754) l. 2
That said, your error implies that you are not returning a hash or array reference from your route? Have you tried dumping your return value to check? Andy
That said, your error implies that you are not returning a hash or array reference from your route? Have you tried dumping your return value to check?
I think the thing that confuses me the most is that this is happening out of the box with the generated app, does this happen for anyone else? If it’s unique to me, then there must be something funny about my environment. Can someone else test this on latest Dancer2: dancer2 -a MyApp && cd MyApp add the line serializer: "JSON" to config.yml plackup ./bin/app.pl -p 5000 -I lib load page in browser or cURL: curl -v http://localhost:5000/ * About to connect() to localhost port 5000 (#0) * Trying ::1... Connection refused * Trying 127.0.0.1... connected * Connected to localhost (127.0.0.1) port 5000 (#0)
GET / HTTP/1.1 User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.14.0.0 zlib/1.2.3 libidn/1.18 libssh2/1.4.2 Host: localhost:5000 Accept: */*
* HTTP 1.0, assume close after body < HTTP/1.0 200 OK < Date: Sat, 20 Dec 2014 20:30:43 GMT < Server: HTTP::Server::PSGI < Server: Perl Dancer2 0.157000 < Content-Type: text/html < Content-Length: 0 < * Closing connection #0 (log from placket console) HTTP::Server::PSGI: Accepting connections at http://0:5000/ [MyApp:106928] core @2014-12-21 07:21:40> looking for get / in /perf/perl/lib/perl5/Plack/Middleware/RemoveRedundantBody.pm l. 14 [MyApp:106928] core @2014-12-21 07:21:40> Entering hook core.app.before_request in /perf/perl/lib/perl5/Dancer2/Core/App.pm l. 1232 [MyApp:106928] core @2014-12-21 07:21:40> Failed to serialize the request: hash- or arrayref expected (not a simple scalar, use allow_nonref to allow this) at /perf/perl/lib/perl5/JSON.pm line 154. in (eval 219) l. 2 [MyApp:106928] core @2014-12-21 07:21:40> Entering hook core.app.after_request in /perf/perl/lib/perl5/Dancer2/Core/App.pm l. 1189 192.168.128.1 - - [21/Dec/2014:07:21:40 +1100] "GET / HTTP/1.1" 200 0 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:34.0) Gecko/20100101 Firefox/34.0” [MyApp:106928] core @2014-12-21 07:30:43> looking for get / in /perf/perl/lib/perl5/Plack/Middleware/RemoveRedundantBody.pm l. 14 [MyApp:106928] core @2014-12-21 07:30:43> Entering hook core.app.before_request in /perf/perl/lib/perl5/Dancer2/Core/App.pm l. 1232 [MyApp:106928] core @2014-12-21 07:30:43> Failed to serialize the request: hash- or arrayref expected (not a simple scalar, use allow_nonref to allow this) at /perf/perl/lib/perl5/JSON.pm line 154. in (eval 219) l. 2 [MyApp:106928] core @2014-12-21 07:30:43> Entering hook core.app.after_request in /perf/perl/lib/perl5/Dancer2/Core/App.pm l. 1189 127.0.0.1 - - [21/Dec/2014:07:30:43 +1100] "GET / HTTP/1.1" 200 0 "-" "curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.14.0.0 zlib/1.2.3 libidn/1.18 libssh2/1.4.2” Matt
I get exactly what you do Blank page and the same error -- Clive Eisen GPG: 75056DD0 On 20 Dec 2014, at 20:37, Matthew Mallard <matt@Q-Technologies.com.au> wrote:
That said, your error implies that you are not returning a hash or array reference from your route? Have you tried dumping your return value to check?
I think the thing that confuses me the most is that this is happening out of the box with the generated app, does this happen for anyone else? If it’s unique to me, then there must be something funny about my environment. Can someone else test this on latest Dancer2:
dancer2 -a MyApp && cd MyApp add the line serializer: "JSON" to config.yml plackup ./bin/app.pl -p 5000 -I lib load page in browser or cURL:
curl -v http://localhost:5000/ * About to connect() to localhost port 5000 (#0) * Trying ::1... Connection refused * Trying 127.0.0.1... connected * Connected to localhost (127.0.0.1) port 5000 (#0)
GET / HTTP/1.1 User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.14.0.0 zlib/1.2.3 libidn/1.18 libssh2/1.4.2 Host: localhost:5000 Accept: */*
* HTTP 1.0, assume close after body < HTTP/1.0 200 OK < Date: Sat, 20 Dec 2014 20:30:43 GMT < Server: HTTP::Server::PSGI < Server: Perl Dancer2 0.157000 < Content-Type: text/html < Content-Length: 0 < * Closing connection #0
(log from placket console)
HTTP::Server::PSGI: Accepting connections at http://0:5000/ [MyApp:106928] core @2014-12-21 07:21:40> looking for get / in /perf/perl/lib/perl5/Plack/Middleware/RemoveRedundantBody.pm l. 14 [MyApp:106928] core @2014-12-21 07:21:40> Entering hook core.app.before_request in /perf/perl/lib/perl5/Dancer2/Core/App.pm l. 1232 [MyApp:106928] core @2014-12-21 07:21:40> Failed to serialize the request: hash- or arrayref expected (not a simple scalar, use allow_nonref to allow this) at /perf/perl/lib/perl5/JSON.pm line 154. in (eval 219) l. 2 [MyApp:106928] core @2014-12-21 07:21:40> Entering hook core.app.after_request in /perf/perl/lib/perl5/Dancer2/Core/App.pm l. 1189 192.168.128.1 - - [21/Dec/2014:07:21:40 +1100] "GET / HTTP/1.1" 200 0 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:34.0) Gecko/20100101 Firefox/34.0” [MyApp:106928] core @2014-12-21 07:30:43> looking for get / in /perf/perl/lib/perl5/Plack/Middleware/RemoveRedundantBody.pm l. 14 [MyApp:106928] core @2014-12-21 07:30:43> Entering hook core.app.before_request in /perf/perl/lib/perl5/Dancer2/Core/App.pm l. 1232 [MyApp:106928] core @2014-12-21 07:30:43> Failed to serialize the request: hash- or arrayref expected (not a simple scalar, use allow_nonref to allow this) at /perf/perl/lib/perl5/JSON.pm line 154. in (eval 219) l. 2 [MyApp:106928] core @2014-12-21 07:30:43> Entering hook core.app.after_request in /perf/perl/lib/perl5/Dancer2/Core/App.pm l. 1189 127.0.0.1 - - [21/Dec/2014:07:30:43 +1100] "GET / HTTP/1.1" 200 0 "-" "curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.14.0.0 zlib/1.2.3 libidn/1.18 libssh2/1.4.2”
Matt
_______________________________________________ dancer-users mailing list dancer-users@dancer.pm http://lists.preshweb.co.uk/mailman/listinfo/dancer-users
Matthew, Andrew and Clive. Prior to Dancer2 0.154000, serialization was only attempted if a reference was returned. From D2 0.154 onwards; if you have defined a serializer for your app, then D2 will *always* attempt to serialize output, including scalars. Sawyer gave an excellent writeup of this on day 11 of the this years advent: http://advent.perldancer.org/2014/11 Hope that helps, Russell. ps. saywer+24 for this years advent entries !!!!!
Hi Russell, Ok, so basically, I need to separate my code between what presents web pages from those bits providing the API (ajax) and set the serializer in the API only. Thanks, Matt On 22 Dec 2014, at 10:05 am, Russell Jenkins <russell.jenkins@strategicdata.com.au> wrote:
Matthew, Andrew and Clive.
Prior to Dancer2 0.154000, serialization was only attempted if a reference was returned.
From D2 0.154 onwards; if you have defined a serializer for your app, then D2 will *always* attempt to serialize output, including scalars.
Sawyer gave an excellent writeup of this on day 11 of the this years advent: http://advent.perldancer.org/2014/11
Hope that helps, Russell.
ps. saywer+24 for this years advent entries !!!!! _______________________________________________ dancer-users mailing list dancer-users@dancer.pm http://lists.preshweb.co.uk/mailman/listinfo/dancer-users
Exactly. :) On Mon, Dec 22, 2014 at 2:17 AM, Matthew Mallard <matt@q-technologies.com.au
wrote:
Hi Russell,
Ok, so basically, I need to separate my code between what presents web pages from those bits providing the API (ajax) and set the serializer in the API only.
Thanks, Matt
On 22 Dec 2014, at 10:05 am, Russell Jenkins < russell.jenkins@strategicdata.com.au> wrote:
Matthew, Andrew and Clive.
Prior to Dancer2 0.154000, serialization was only attempted if a reference was returned.
From D2 0.154 onwards; if you have defined a serializer for your app, then D2 will *always* attempt to serialize output, including scalars.
Sawyer gave an excellent writeup of this on day 11 of the this years advent: http://advent.perldancer.org/2014/11
Hope that helps, Russell.
ps. saywer+24 for this years advent entries !!!!! _______________________________________________ dancer-users mailing list dancer-users@dancer.pm http://lists.preshweb.co.uk/mailman/listinfo/dancer-users
_______________________________________________ dancer-users mailing list dancer-users@dancer.pm http://lists.preshweb.co.uk/mailman/listinfo/dancer-users
participants (6)
-
Andrew Beverley -
Clive Eisen -
Matthew Mallard -
Matthew Mallard -
Russell Jenkins -
Sawyer X