I entirely agree - there should never be explicit code like this needed. However, currently, if you remove it - then the tests fail.
This may be as the tests are utterly wrong, or it may be as there is another bug we're not seeing / aware of. If you could suggest a way to resolve this issue (either by fixing something more than just removing these lines, or by deciding the tests are wrong and correcting them), then I'd be fully in support of fixing this. Cheers t0m On 1 Oct 2012, at 22:14, Bill Moseley wrote: > This code looks wrong to me. I don't think that utf8 line should be there. > > sub freeze { > my ( $self, @args ) = @_; > my $json = JSON::Any->objToJson( $self->pack(@args) ); > utf8::decode($json) if !utf8::is_utf8($json) and > utf8::valid($json); # if it's valid utf8 mark it as such > return $json; > } > > > Normally, I would want to take a structure that might include character > data (i.e utf8 flag is on) and serialize it into (utf8) encoded bytes. So > JSON::Any->objToJson does that. In other words: > > my %utf8_char = ( foo => 'hello ' . "\N{U+263A}" ); > my $return_trip = JSON::Any->jsonToObj( JSON::Any->objToJson( \%utf8_char ) > ); > print Encode::is_utf8( $return_trip->{foo} ) ? "Yes utf8\n" : "Nope, not > ut8\n"; > > > Works as expected: > > Yes utf8 > > > So, the "freeze" method quoted above first returns the utf8-encoded string > then does this: > > utf8::decode($json) if !utf8::is_utf8($json) and > utf8::valid($json); # if it's valid utf8 mark it as such > > > turns the string back into utf8 characters. > > As a result when I send that frozen serialized string some place I get Wide > Character errors. > > > > -- > Bill Moseley > mose...@hank.org