
alejandro.imass at gmail
Sep 28, 2009, 8:46 AM
Post #1 of 5
(1197 views)
Permalink
|
|
Catalyst::Controller::REST JSON Serialization/Encoding Problem
|
|
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 _______________________________________________ List: Catalyst [at] lists Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst [at] lists/ Dev site: http://dev.catalyst.perl.org/
|