[dancer-users] Incorrect attempts to serialize HTML

Andrew Beverley andy at andybev.com
Tue Nov 11 18:06:02 GMT 2014


On Thu, 2014-10-09 at 12:47 +0100, Andrew Beverley wrote:
> Hi guys,
> 
> I apologise in advance that this is rather vague, but I'm hoping that
> someone might be able to point me in the right direction of where I
> should be looking.
> 
> I'm getting some strange problems with Dancer2 and the "auto
> serializer". I have
> 
>     set serializer => 'JSON';
> 
> in my app, but under some circumstances it is trying to serialize HTML
> content, with the subsequent errors that you would expect of such an
> action.
> 
> The problems seem to be related to my error handling (using
> Log::Report). My implementation is currently rather poor and
> complicated, so I won't go into the details here, but I wondered whether
> someone can point me to the relevant parts of the Dancer2 code that I
> should start poking around in (in particular the code which detects
> whether to serialize the data). I've looked at serialize() in
> Serializer::Mutuble, but as far as I can tell this function is not being
> called. Where else should I look?
> 
> If I remove the aforementioned serializer statement then everything
> works as expected.

Just thought I'd follow up on this. It turned out that the problem was
that my text to render to the screen was a reference to an object that
normally stringified into the required text (Log::Report::Message).
However, because the serializer was simply checking for a reference, the
object didn't have a chance to stringify itself, and instead an attempt
was made to convert the object into JSON.

The fix was easy (just stringify first), but I did wonder whether a
better error message could be displayed somehow, as it took me rather a
long time to debug. I came to the conclusion that it couldn't, but if
anyone has any ideas then please let me know.

Andy




More information about the dancer-users mailing list