PartialDenormalizationException example

'title' => 'This value should be of type int.',
                    'template' => 'This value should be of type {{ type }}.',
                    'parameters' => [
                        '{{ type }}' => 'int',
                    ],
                    'hint' => 'Invalid value',
                ],
            ],
        ];

        $exception = NotNormalizableValueException::createForUnexpectedDataType('Invalid value', null, ['int'], 'foo', true);
        $exception = new PartialDenormalizationException('Validation Failed', [$exception]);
        $exception = new HttpException(422, 'Validation Failed', $exception);
        $this->assertSame($expected$this->normalizer->normalize(FlattenException::createFromThrowable($exception), null, ['exception' => $exception]));
    }

    public function testNormalizeValidationFailedException()
    {
        $this->normalizer->setSerializer(new Serializer([new ConstraintViolationListNormalizer()]));

        $expected = [
            'type' => 'https://symfony.com/errors/validation',
            'title' => 'Validation Failed',
            
if (!$normalizer) {
            throw new NotNormalizableValueException(sprintf('Could not denormalize object of type "%s", no supporting normalizer found.', $type));
        }

        if (isset($context[DenormalizerInterface::COLLECT_DENORMALIZATION_ERRORS])) {
            unset($context[DenormalizerInterface::COLLECT_DENORMALIZATION_ERRORS]);
            $context['not_normalizable_value_exceptions'] = [];
            $errors = &$context['not_normalizable_value_exceptions'];
            $denormalized = $normalizer->denormalize($data$type$format$context);
            if ($errors) {
                throw new PartialDenormalizationException($denormalized$errors);
            }

            return $denormalized;
        }

        return $normalizer->denormalize($data$type$format$context);
    }

    public function getSupportedTypes(?string $format): array
    {
        return ['*' => false];
    }
if (!$normalizer) {
            throw new NotNormalizableValueException(sprintf('Could not denormalize object of type "%s", no supporting normalizer found.', $type));
        }

        if (isset($context[DenormalizerInterface::COLLECT_DENORMALIZATION_ERRORS])) {
            unset($context[DenormalizerInterface::COLLECT_DENORMALIZATION_ERRORS]);
            $context['not_normalizable_value_exceptions'] = [];
            $errors = &$context['not_normalizable_value_exceptions'];
            $denormalized = $normalizer->denormalize($data$type$format$context);
            if ($errors) {
                throw new PartialDenormalizationException($denormalized$errors);
            }

            return $denormalized;
        }

        return $normalizer->denormalize($data$type$format$context);
    }

    public function getSupportedTypes(?string $format): array
    {
        return ['*' => false];
    }
Home | Imprint | This part of the site doesn't use cookies.