Hi Vlad, you can customize the serializer in the application package by setting the engine config first, then the serializer option:
# in MyApp::Controller
use Dancer2;
set engines => {
serializer => {
JSON => {
pretty => 1,
allow_blessed => 1,
canonical => 0,
utf8 => 1,
},
},
};
set serializer => 'JSON';
get '/config' => sub {
return config;
};
Output in browser when requesting /config is something like:
{
"apphandler" : "PSGI",
# bunch of stuff snipped ...
"engines" : {
"serializer" : {
"JSON" : {
"utf8" : 1,
"canonical" : 0,
"allow_blessed" : 1,
"pretty" : 1
}
}
},
"serializer" : null,
"static_handler" : 1,
"host" : "0.0.0.0"
}
Note that, oddly, the config shows the value of serializer as null, but as the format of the output shows, the settings are being implemented.
Hope this helps!
The way forward always starts with a minimal test.
|