| Apache2-REST documentation | Contained in the Apache2-REST distribution. |
Apache2::REST::Writer::json - Apache2::REST::Response Writer for json
Getter
Returns the response as json UTF8 bytes for output.
| Apache2-REST documentation | Contained in the Apache2-REST distribution. |
package Apache2::REST::Writer::json ; use strict ; use JSON::XS ; use Data::Dumper ;
sub new{ my ( $class ) = @_; return bless {} , $class; }
sub mimeType{ return 'application/json' ; }
sub asBytes{ my ($self, $resp ) = @_ ; #Shallow unblessed copy of response # JSON wont output blessed object not implementing the TO_JSON request my %resp = %$resp ; my $coder = JSON::XS->new->allow_blessed(0)->utf8; ## These are bytes. This is correct. return $coder->encode(\%resp) ; } 1;