Skip to content

Commit

Permalink
minor #52716 [Serializer] do not detect the deserialization_path cont…
Browse files Browse the repository at this point in the history
…ext value twice (xabbuh)

This PR was merged into the 6.3 branch.

Discussion
----------

[Serializer] do not detect the deserialization_path context value twice

| Q             | A
| ------------- | ---
| Branch?       | 6.3
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Issues        |
| License       | MIT

#52713 must not be applied on 6.3+ as the logic is already part of the `getAttributeDenormalizationContext()` method introduced in #46680.

Commits
-------

9b027a5 do not detect the deserialization_path context value twice
  • Loading branch information
nicolas-grekas committed Nov 24, 2023
2 parents 09e2cba + 9b027a5 commit 9f87a34
Showing 1 changed file with 1 addition and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -342,15 +342,12 @@ protected function instantiateObject(array &$data, string $class, array &$contex
$missingConstructorArguments = [];
$params = [];
$unsetKeys = [];
$objectDeserializationPath = $context['deserialization_path'] ?? null;

foreach ($constructorParameters as $constructorParameter) {
$paramName = $constructorParameter->name;
$attributeContext = $this->getAttributeDenormalizationContext($class, $paramName, $context);
$key = $this->nameConverter ? $this->nameConverter->normalize($paramName, $class, $format, $context) : $paramName;

$context['deserialization_path'] = $objectDeserializationPath ? $objectDeserializationPath.'.'.$paramName : $paramName;

$allowed = false === $allowedAttributes || \in_array($paramName, $allowedAttributes);
$ignored = !$this->isAllowedAttribute($class, $paramName, $format, $context);
if ($constructorParameter->isVariadic()) {
Expand Down Expand Up @@ -406,15 +403,13 @@ protected function instantiateObject(array &$data, string $class, array &$contex
sprintf('Failed to create object because the class misses the "%s" property.', $constructorParameter->name),
$data,
['unknown'],
$objectDeserializationPath,
$context['deserialization_path'] ?? null,
true
);
$context['not_normalizable_value_exceptions'][] = $exception;
}
}

$context['deserialization_path'] = $objectDeserializationPath;

if ($missingConstructorArguments) {
throw new MissingConstructorArgumentsException(sprintf('Cannot create an instance of "%s" from serialized data because its constructor requires the following parameters to be present : "$%s".', $class, implode('", "$', $missingConstructorArguments)), 0, null, $missingConstructorArguments, $class);
}
Expand Down

0 comments on commit 9f87a34

Please sign in to comment.