2024-05-06 20:40:05 +00:00
|
|
|
---
|
2024-10-30 17:04:36 +00:00
|
|
|
date: 20201117
|
2024-05-06 20:40:05 +00:00
|
|
|
id: 31b5b357-abf4-4abb-9241-1190cbe61f96
|
|
|
|
title: UUID Normalizer
|
|
|
|
---
|
|
|
|
|
|
|
|
# Description
|
|
|
|
|
|
|
|
[UUIDs](20201116131815-symfony_uuid_component) are automatically
|
|
|
|
serialized/deserialized as expected.
|
|
|
|
|
|
|
|
# Syntax
|
|
|
|
|
|
|
|
``` php
|
|
|
|
// src/Entity/Product.php
|
|
|
|
namespace App\Entity;
|
|
|
|
|
|
|
|
use Doctrine\ORM\Mapping as ORM;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ORM\Entity(repositoryClass="App\Repository\ProductRepository")
|
|
|
|
*/
|
|
|
|
class Product
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @ORM\Column(type="uuid")
|
|
|
|
*/
|
|
|
|
private $id;
|
|
|
|
|
|
|
|
// ...
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
``` php
|
|
|
|
$product = new Product();
|
|
|
|
$jsonContent = $serializer->serialize($product, 'json');
|
|
|
|
// $jsonContent contains {"id":"9b7541de-6f87-11ea-ab3c-9da9a81562fc","...":"..."}
|
|
|
|
```
|