Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2ef0003

Browse files
committed
Support unallowed extra attributes
1 parent df30c9b commit 2ef0003

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use Symfony\Component\Serializer\Exception\LogicException;
2424
use Symfony\Component\Serializer\Exception\NotNormalizableValueException;
2525
use Symfony\Component\Serializer\Exception\RuntimeException;
26+
use Symfony\Component\Serializer\InvariantViolation;
2627
use Symfony\Component\Serializer\Mapping\AttributeMetadataInterface;
2728
use Symfony\Component\Serializer\Mapping\ClassDiscriminatorFromClassMetadata;
2829
use Symfony\Component\Serializer\Mapping\ClassDiscriminatorResolverInterface;
@@ -353,11 +354,15 @@ public function denormalize($data, string $type, string $format = null, array $c
353354
}
354355
}
355356

356-
if ([] !== $invariantViolations) {
357-
return DenormalizationResult::failure($invariantViolations);
358-
}
359-
360357
if ($context[self::COLLECT_INVARIANT_VIOLATIONS] ?? false) {
358+
if (!empty($extraAttributes)) {
359+
$invariantViolations[] = new InvariantViolation($data, sprintf('Extra attributes are not allowed ("%s" are unknown).', implode('", "', $extraAttributes)));
360+
}
361+
362+
if ([] !== $invariantViolations) {
363+
return DenormalizationResult::failure($invariantViolations);
364+
}
365+
361366
return DenormalizationResult::success($object);
362367
}
363368

0 commit comments

Comments
 (0)