From: John Napiorkowski Date: Tue, 5 Dec 2017 15:03:41 +0000 (-0500) Subject: Merge branch 'runarbu-master' X-Git-Tag: v1.21~1 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=9819a955ab18ead8943cc8a912dcddcacbade74b;hp=370367cb80b925e50a4ea1bc759b06d1466f2627;p=catagits%2FCatalyst-Action-REST.git Merge branch 'runarbu-master' --- 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 3c9ec67..b9c10d0 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);