This library allows you to serialize and deserialize ramsey/uuid UUIDs when using JMS Serializer library.
- Install the latest version with
composer require mhujer/jms-serializer-uuid
- Register a custom handler to JMS Serializer (documentation)
<?php
$builder
->configureHandlers(function(JMS\Serializer\Handler\HandlerRegistry $registry) {
$registry->registerSubscribingHandler(new \Mhujer\JmsSerializer\Uuid\UuidSerializerHandler());
})
;
or if you are using Symfony, register it as a tagged service in services.yaml
:
Mhujer\JmsSerializer\Uuid\UuidSerializerHandler:
tags:
- { name: jms_serializer.subscribing_handler }
Then you can use the uuid
type for serialization or deserialization:
<?php
use JMS\Serializer\Annotation as JMS;
class User
{
/**
* @JMS\Type("uuid")
* @var \Ramsey\Uuid\UuidInterface
*/
public $id;
}
Works with PHP 8.0 or higher.
Bugs and feature request are tracked on GitHub
- #17 handle non-stringable values
- #10 Add support for ramsey/uuid v4 (thank you @simPod!)
- #3 require PHP 7.1, potential BC breaks because of added type-hints
- #1 fixed serialization to XML
- initial release