<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">Dear Russel, please see additional information below. I really appreciate your help.<div class=""><br class=""></div><div class=""><br class=""><blockquote type="cite" class="">On Sep 27, 2015, at 10:41 PM, Russell Jenkins <<a href="mailto:russell.jenkins@strategicdata.com.au" class="">russell.jenkins@strategicdata.com.au</a>> wrote:<br class=""><br class="">On 27/09/2015 11:54 am, Robert Smith wrote:<br class=""><blockquote type="cite" class="">JSON is enabled in config.yml<br class=""><br class="">serializer: "JSON"<br class="">engines:<br class=""> serializer:<br class=""> JSON:<br class=""> pretty: 1<br class=""> allow_blessed: 1<br class=""> canonical: 0<br class=""> utf8: 1<br class=""><br class="">YAML is working fine as a serializer using the the following method:<br class="">JSON prints mojibake when using the serializer using the following method:<br class=""><br class=""><br class="">get '/establishments' => sub {<br class=""> my $sql = 'select * from establishments';<br class=""> my $sth = database->prepare($sql) or die database->errstr;<br class=""> $sth->execute or die $sth->errstr;<br class=""> #the following is broken in Dancer2<br class=""> return \%{$sth->fetchall_hashref('id')};<br class="">};<br class=""><br class=""></blockquote><br class=""><br class="">Provided you get characters (not octets) back from the database the above "just works".<br class="">If you are getting octets back they will get encoded again (with their default serializer params).<br class="">All Dancer2 serializers expect characters and return octets for adding to the response body.<br class=""><br class=""></blockquote><div class=""><br class=""></div><div class="">It doesn’t "just work” however it seems. If this was true, shouldn’t the YAML serializer be having the same issue? Whatever my database is returning works perfectly fine with the YAML serializer, but not the JSON serializer.</div><div class=""><br class=""></div><div class="">Here is my config.yml</div><div class=""><br class=""></div><div class=""><br class="">appname: "BeaconTrackerAPI"<br class="">layout: "main"<br class="">charset: "UTF-8"<br class="">serializer: "JSON"<br class="">engines:<br class=""> serializer:<br class=""> JSON:<br class=""> pretty: 1<br class=""> allow_blessed: 1<br class=""> canonical: 0<br class=""># ascii: 1<br class="">#utf8: 1</div><div class=""><br class="">template: "simple"<br class="">plugins:<br class=""> Database:<br class=""> driver: 'Pg'<br class=""> database: ‘***************'<br class=""> host: 'localhost'<br class=""> port: 5432<br class=""> username: ‘*******'<br class=""> password: '********'<br class=""> connection_check_threshold: 10<br class=""> on_connect_do: ["SET NAMES 'utf8'"]<br class=""><br class=""><br class=""></div><div class="">Here is the method used in both the JSON and YAML tests:</div><div class=""><br class=""></div><div class="">get '/establishments' => sub {<br class=""> my $sql = 'select * from establishments';<br class=""> my $sth = database->prepare($sql) or die database->errstr;<br class=""> $sth->execute or die $sth->errstr;<br class=""> #return to_json(\%{$sth->fetchall_hashref('id')}, { utf8 => 0 });<br class=""> #the following is broken in Dancer2 serializer<br class=""> return \%{$sth->fetchall_hashref('id')};<br class="">};</div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">Here is the output to the browser (broken):</div><div class=""><br class=""></div><div class=""><div class="">{</div><div class=""> "1" : {</div><div class=""> "client_id" : "1123",</div><div class=""> "name" : "WANSecurity, K.K.",</div><div class=""> "address" : "æ±äº¬éƒ½æ¸‹è°·åŒºä¸ŠåŽŸï¼’−48−12 ã¨ã‚ˆä»£ã€…木上原コーãƒï¼ƒï¼’ï¼ï¼‘",</div><div class=""> "id" : "1"</div><div class=""> }</div><div class="">}</div></div><div class=""><br class=""></div><div class=""><img height="187" width="919" apple-width="yes" apple-height="yes" apple-inline="yes" id="C605E0DD-FE97-4C09-8EC9-229EE2721D2C" src="cid:848CDE08-F155-44E1-8E57-1C280F663DB2@corp.wansecurity.com" class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">Here is output from my terminal via psql (Looks good):</div><div class=""><br class=""></div><div class="">beacon_tracker=> select * from establishments;<br class=""> id | name | address | client_id<br class="">----+-------------------+-----------------------------------------------------------+-----------<br class=""> 1 | WANSecurity, K.K. | 東京都渋谷区上原2−48 | 1123</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">Is this the expected behavior?</div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">Here is the output from YAML when using the YAML serializer (Looks good):</div><div class=""><br class=""></div><div class="">---<br class="">1:<br class=""> address: 東京都渋谷区上原2−48<br class=""> client_id: 1123<br class=""> id: 1<br class=""> name: 'WANSecurity, K.K.'</div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">YAML looks exactly like what I would expect to see, right out of the box. Something strange is happening with the JSON serializer it seems.</div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">Am I missing anything?</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">-Robert</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><br class=""><blockquote type="cite" class=""><br class="">Note the #686 is about a different issue; the to_json, to_yaml and to_dumper keywords.<br class="">Their implementation also returns octets, so when those keywords are used as the return<br class="">form a route the response is double encoded.<br class=""><br class=""><br class="">Hope that helps,<br class=""> Russell.<br class=""><br class="">_______________________________________________<br class="">dancer-users mailing list<br class=""><a href="mailto:dancer-users@dancer.pm" class="">dancer-users@dancer.pm</a><br class="">http://lists.preshweb.co.uk/mailman/listinfo/dancer-users<br class=""></blockquote><br class=""></div></body></html>