.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Dancer2::Serializer::JSON 3pm" .TH Dancer2::Serializer::JSON 3pm "2023-12-15" "perl v5.36.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Dancer2::Serializer::JSON \- Serializer for handling JSON data .SH "VERSION" .IX Header "VERSION" version 1.1.0 .SH "DESCRIPTION" .IX Header "DESCRIPTION" This is a serializer engine that allows you to turn Perl data structures into \&\s-1JSON\s0 output and vice-versa. .SH "ATTRIBUTES" .IX Header "ATTRIBUTES" .SS "content_type" .IX Subsection "content_type" Returns 'application/json' .SH "METHODS" .IX Header "METHODS" .SS "serialize($content)" .IX Subsection "serialize($content)" Serializes a Perl data structure into a \s-1JSON\s0 string. .SS "deserialize($content)" .IX Subsection "deserialize($content)" Deserializes a \s-1JSON\s0 string into a Perl data structure. .SH "FUNCTIONS" .IX Header "FUNCTIONS" .SS "from_json($content, \e%options)" .IX Subsection "from_json($content, %options)" This is an helper available to transform a \s-1JSON\s0 data structure to a Perl data structures. .SS "to_json($content, \e%options)" .IX Subsection "to_json($content, %options)" This is an helper available to transform a Perl data structure to \s-1JSON.\s0 .PP Calling this function will \fBnot\fR trigger the serialization's hooks. .ie n .SS "Configuring the \s-1JSON\s0 Serializer using ""set engines""" .el .SS "Configuring the \s-1JSON\s0 Serializer using \f(CWset engines\fP" .IX Subsection "Configuring the JSON Serializer using set engines" The \s-1JSON\s0 serializer options can be configured via \f(CW\*(C`set engines\*(C'\fR. The most common settings are: .IP "allow_nonref" 4 .IX Item "allow_nonref" Ignore non-ref scalars returned from handlers. With this set the \*(L"Hello, World!\*(R" handler returning a string will be dealt with properly. .PP Set engines should be called prior to setting \s-1JSON\s0 as the serializer: .PP .Vb 10 \& set engines => \& { \& serializer => \& { \& JSON => \& { \& allow_nonref => 1 \& }, \& } \& }; \& \& set serializer => \*(AqJSON\*(Aq; \& set content_type => \*(Aqapplication/json\*(Aq; .Ve .SS "Returning non-JSON data." .IX Subsection "Returning non-JSON data." Handlers can return non-JSON via \f(CW\*(C`send_as\*(C'\fR, which overrides the default serializer: .PP .Vb 6 \& get \*(Aq/\*(Aq => \& sub \& { \& send_as html => \& q{Welcome to the root of all evil...
step into my office.} \& }; .Ve .PP Any other non-JSON returned format supported by 'send_as' can be used. .SH "AUTHOR" .IX Header "AUTHOR" Dancer Core Developers .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" This software is copyright (c) 2023 by Alexis Sukrieh. .PP This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.