<?php

namespace App\Framework\Cache\Serializer;

use App\Framework\Cache\Serializer;
use JsonException;

final readonly class JsonSerializer implements Serializer
{
    /**
     * @throws JsonException
     */
    public function serialize(mixed $value): string
    {
        return json_encode($value, JSON_THROW_ON_ERROR);
    }

    /**
     * @throws JsonException
     */
    public function unserialize(string $value): mixed
    {
        return json_decode($value, true, 512, JSON_THROW_ON_ERROR);
    }
}
