[Catalyst] Catalyst::Controller::REST JSON Serialization/Encoding
Problem
Alejandro Imass
alejandro.imass at gmail.com
Mon Sep 28 15:46:35 GMT 2009
Hi,
The current version (0.77) seems to be encoding JSON with UTF-8 data
wrong. In fact. I have noticed this problem since earlier versions,
and it's still present in 0.77. I think that with JSON v2 many things
changed and using encode_json is actually re-encoding the data, if the
data is already in UTF-8. I have found that by changing to_json
instead of encode_json it all works perfectly. The JSON pod is very
confusing when it comes to encoding and has a complete section on it
"A FEW NOTES ON UNICODE AND PERL" so I am pretty sure after reading it
several times that there is s a problem when using encode_json and we
should be using to_json.
The current maintainer should verify this, but I would suggest to
change encode_json for to_json like so:
In file Catalyst::Action::Serialize::JSON
-----------------------------------------------
#use JSON qw(encode_json);
use JSON qw(to_json);
In sub serialize()
---------------------
sub serialize {
my $self = shift;
#encode_json( shift );
to_json( shift );
}
Also, I don't think that JSON::XS is explicitly necessary because from
the JSON::XS v2 pod
# Note that JSON version 2.0 and above will automatically use JSON::XS
# if available, at virtually no speed overhead either, so you should
# be able to just:
use JSON;
Well, that's it for now, but I can verify that by using to_json it
actually solves my encoding problems.
Best,
Alejandro Imass
More information about the Catalyst
mailing list