sukria/Dancer — Issue #749: to_json doesn't play well with Dancer (utf8)
Author: ambs
Created: 2012-02-21 13:34:28+00:00
State: open

Hello,

Recently a request to encode to UTF8 by default when using to_json was accepted. I think I voted in favor of it as well. But I think it was not a good idea.

As a test case, I tried to ``dancer -a Foo`` and edit ``lib/Foo.pm`` to this content:

```
package Foo;
use Dancer ':syntax';

use utf8;

our $VERSION = '0.1';

get '/' => sub {
content_type 'application/json';
to_json( { hey => 'España' } );
};

true;
```

Note the ``use utf8``, important if we use unicode in our source code. Also, note that ``config.yml`` by default sets ``utf-8`` as the default charset.

Put the website to run, and fetch ``/``. You get a double encoded UTF-8 content.

Why? Because ``to_json`` is encoding to UTF-8, and Dancer reencodes it.
Although I agree that it might be helpful to have ``to_json`` encoding to UTF-8, I think it is better to have it playing well and cleanly with Dancer (well, it is a feature for Dancer, right?).

So, I see two options:
1) remove that patch
2) make Dancer not reencode if it is already encoded.

Cheers