wiki/content/20201117103957-uuid_normalizer.md

38 lines
662 B
Markdown

---
date: 2020-11-17
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","...":"..."}
```