wiki/content/20201117103957-uuid_normalizer.md

39 lines
662 B
Markdown
Raw Normal View History

2024-05-06 20:40:05 +00:00
---
2024-10-29 18:27:12 +00:00
date: 2020-11-17
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","...":"..."}
```