[dancer-users] JSON Serialiser

Zahir Lalani ZahirLalani at oliver.agency
Sun Jul 19 10:32:08 BST 2015

--From: dancer-users [mailto:dancer-users-bounces at dancer.pm] On Behalf Of Sawyer X
--Sent: 19 July 2015 00:31
--To: Perl Dancer users mailing list
--Subject: Re: [dancer-users] JSON Serialiser

--I don't understand this email. T abundance of HTML in your message is quite disruptive.

My apologies for the confusion. Let me try again…..

I had code which was working just fine two months ago. It relied on the automatic JSON deserialise + blessed objects. I was able to "return" a Moo object as a response to a REST request and the output would correctly show the json. So the basic format for this is:

get '/xxxx' => sub {
     return AnObject->new;

AnObject has TO_JSON implemented.

I came back to this project after 2 months and found that it no longer worked - I would get an error of the form " Unrecognized response type from route". I found  a thread from April 15th which showed the same issue and a solution. (this is what I tried to include!). The solution was to wrap the response object in a hash as below:

get '/xxxx' => sub {
    return { result => AnObject->new };

My question is: which should be the correct way. My previous way worked and then something must have changed. Was the change deliberate? I have no issue with the solution above, I just want to understand whether this is the expected behaviour now.


More information about the dancer-users mailing list