This bundle provides some extra features for serialization.
# app/config.yml
hshn_serializer_extra:
authority:
classes:
AcmeBundle\Entity\Blog:
attributes: OWNER
/** @var $serializer JMS\Serializer\Serializer */
$json = $serializer->serialize($blog, 'json');
The access authorities provided by AuthorizationCheckerInterface::isGranted()
will be exported to the attribute '_authority' when an object was serialized.
{
"key": "value",
"_authority": {
"OWNER": true
}
}
# app/config.yml
hshn_serializer_extra:
authority:
export_to: "my_authority"
{
"key": "value",
"my_authority": {
"OWNER": true
}
}
# app/config.yml
hshn_serializer_extra:
authority:
classes:
AcmeBundle\Entity\Blog:
attributes: [OWNER]
max_depth: 0 # default -1 (unlimited)
class Blog
{
}
class User
{
/**
* @var Blog
*/
private $blog;
}
$serializer->serialize($blog, 'json'); // will export the blog authorities (depth 0)
$serializer->serialize($user, 'json'); // will NOT export the blog authorities (depth 1)
This feature require VichUploaderBundle
# app/config.yml
hshn_serializer_extra:
vich_uploader:
classes:
AcmeBundle\Entity\Blog:
files:
- { property: picture }
- { property: picture, export_to: image }
/** @var $serializer JMS\Serializer\Serializer */
$json = $serializer->serialize($blog, 'json');
Generated URLs will be exported when serializing an object.
{
"picture": "/url/to/picture",
"image": "/url/to/picture"
}
This feature require LiipImagineBundle
Adding a filter name specification to a file configuration.
# app/config.yml
hshn_serializer_extra:
vich_uploader:
classes:
AcmeBundle\Entity\Blog:
files:
- { property: picture }
- { property: picture, export_to: image, filter: thumbnail }
{
"picture": "/url/to/picture",
"image": "/url/to/thumbnail/picture"
}