vinyvicente/doctrine-point-type

Serializer support for null values

Closed this issue · 1 comments

A serializer has been added by @fullbl (#13) but it does not support null values.

If I change the serializer denormalize to following it supports both null values and Point type.
Should I create pull request for this or is there a better way?

/**
     * @param null|array{latitude:float,longitude:float} $data
     *
     * @return Point
     */
    public function denormalize($data, string $type, string $format = null, array $context = []): ?Point
    {
        if (isset($data)) {
            return new Point($data['latitude'], $data['longitude']);
        }

        return null;
    }

Another option would be to throw a NotNormalizableValueException or an InvalidArgumentException. I see that Symfony uses both (f.e.: https://github.com/symfony/serializer/blob/6.1/Normalizer/BackedEnumNormalizer.php)