wiki/content/20201117103957-uuid_normalizer.md

662 B

date id title
2020-11-17 31b5b357-abf4-4abb-9241-1190cbe61f96 UUID Normalizer

Description

UUIDs are automatically serialized/deserialized as expected.

Syntax

// 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;

    // ...
}
$product = new Product();
$jsonContent = $serializer->serialize($product, 'json');
// $jsonContent contains {"id":"9b7541de-6f87-11ea-ab3c-9da9a81562fc","...":"..."}