From: Runar Buvik Date: Tue, 3 Nov 2015 09:44:33 +0000 (-0500) Subject: New option json_options_encode to set JSON options for output X-Git-Tag: v1.21~1^2^2 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Action-REST.git;a=commitdiff_plain;h=43e4baa3655de11012897d060a6169dc81b0b4ec New option json_options_encode to set JSON options for output It is good to be able to set flags like pretty and indent when making json. --- diff --git a/lib/Catalyst/Action/Serialize/JSON.pm b/lib/Catalyst/Action/Serialize/JSON.pm index 9d5f304..e618248 100644 --- a/lib/Catalyst/Action/Serialize/JSON.pm +++ b/lib/Catalyst/Action/Serialize/JSON.pm @@ -20,6 +20,12 @@ sub execute { my $self = shift; my ( $controller, $c ) = @_; + if (my $options = $controller->{json_options_encode}) { + foreach my $opt (keys %$options) { + $self->encoder->$opt( $options->{$opt} ); + } + } + my $stash_key = ( $controller->{'serialize'} ? $controller->{'serialize'}->{'stash_key'} : diff --git a/lib/Catalyst/Controller/REST.pm b/lib/Catalyst/Controller/REST.pm index 428d749..12568f7 100644 --- a/lib/Catalyst/Controller/REST.pm +++ b/lib/Catalyst/Controller/REST.pm @@ -147,11 +147,22 @@ L installed. The C content type is supported but is deprecated and you will receive warnings in your log. You can also add a hash in your controller config to pass options to the json object. +There are two options. C are used when decoding incoming JSON, and C +is used when encoding JSON for output. + For instance, to relax permissions when deserializing input, add: + __PACKAGE__->config( json_options => { relaxed => 1 } ) +To indent the JSON output so it becomes more human readable, add: + + __PACKAGE__->config( + json_options_encode => { indent => 1 } + ) + + =item * C => C If a callback=? parameter is passed, this returns javascript in the form of: $callback($serializedJSON);