34 lines
631 B
Perl
34 lines
631 B
Perl
use 5.38.0;
|
|
|
|
package Dancer2::Serializer::JsonApi;
|
|
|
|
use Dancer2::Plugin::JsonApi::Registry;
|
|
use Dancer2::Serializer::JSON;
|
|
|
|
use Moo;
|
|
|
|
has content_type => ( is => 'ro', default => 'application/vnd.api+json' );
|
|
|
|
with 'Dancer2::Core::Role::Serializer';
|
|
|
|
has registry => (
|
|
is => 'rw',
|
|
default => sub { Dancer2::Plugin::JsonApi::Registry->new }
|
|
);
|
|
|
|
has json_serializer => (
|
|
is => 'ro',
|
|
default => sub { Dancer2::Serializer::JSON->new }
|
|
);
|
|
|
|
sub serialize {
|
|
my ( $self, $data ) = @_;
|
|
|
|
return $self->json_serializer->serialize(
|
|
$self->registry->serialize(@$data) );
|
|
}
|
|
|
|
sub deserialize { ... }
|
|
|
|
1;
|