Elastica icon indicating copy to clipboard operation
Elastica copied to clipboard

Remove json utils methods and json custom exception

Open deguif opened this issue 3 years ago • 2 comments

deguif avatar Dec 07 '22 13:12 deguif

my 2 cents: what about to no remove JSON class and improve it instead to smth like:

class JsonEncoder
{
    private function __construct()
    {
    }

    public static function encode(mixed $value, int $flags = null, int $maxDepth = 512): string
    {
        $flags ??= \JSON_HEX_TAG | \JSON_HEX_APOS | \JSON_HEX_AMP | \JSON_HEX_QUOT | \JSON_PRESERVE_ZERO_FRACTION;

        try {
            return json_encode($value, $flags | \JSON_THROW_ON_ERROR, $maxDepth);
        } catch (\JsonException $e) {
            throw new InvalidArgumentException('Invalid value for "json" option: '.$e->getMessage());
        }
    }

and the same for json_decode.

The idea is pretty simple - tons of json_encode(decode) around the codebase

sidz avatar Dec 07 '22 19:12 sidz