function Serializer::denormalize
Same name in this branch
- 11.1.x core/modules/jsonapi/src/Serializer/Serializer.php \Drupal\jsonapi\Serializer\Serializer::denormalize()
Throws
PartialDenormalizationException Occurs when one or more properties of $type fails to denormalize
Overrides DenormalizerInterface::denormalize
3 calls to Serializer::denormalize()
- Serializer::denormalize in core/
modules/ jsonapi/ src/ Serializer/ Serializer.php - Denormalizes data back into an object of the given class.
- Serializer::denormalize in core/
modules/ jsonapi/ src/ Serializer/ Serializer.php - Denormalizes data back into an object of the given class.
- Serializer::deserialize in vendor/
symfony/ serializer/ Serializer.php - Deserializes data into the given type.
1 method overrides Serializer::denormalize()
- Serializer::denormalize in core/
modules/ jsonapi/ src/ Serializer/ Serializer.php - Denormalizes data back into an object of the given class.
File
-
vendor/
symfony/ serializer/ Serializer.php, line 189
Class
- Serializer
- Serializer serializes and deserializes data.
Namespace
Symfony\Component\SerializerCode
public function denormalize(mixed $data, string $type, ?string $format = null, array $context = []) : mixed {
if (isset($context[DenormalizerInterface::COLLECT_DENORMALIZATION_ERRORS], $context['not_normalizable_value_exceptions'])) {
throw new LogicException('Passing a value for "not_normalizable_value_exceptions" context key is not allowed.');
}
$normalizer = $this->getDenormalizer($data, $type, $format, $context);
// Check for a denormalizer first, e.g. the data is wrapped
if (!$normalizer && isset(self::SCALAR_TYPES[$type])) {
if (!('is_' . $type)($data)) {
throw NotNormalizableValueException::createForUnexpectedDataType(\sprintf('Data expected to be of type "%s" ("%s" given).', $type, get_debug_type($data)), $data, [
$type,
], $context['deserialization_path'] ?? null, true);
}
return $data;
}
if (!$this->normalizers) {
throw new LogicException('You must register at least one normalizer to be able to denormalize objects.');
}
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) {
// merge errors so that one path has only one error
$uniqueErrors = [];
foreach ($errors as $error) {
if (null === $error->getPath()) {
$uniqueErrors[] = $error;
continue;
}
$uniqueErrors[$error->getPath()] = $uniqueErrors[$error->getPath()] ?? $error;
}
throw new PartialDenormalizationException($denormalized, array_values($uniqueErrors));
}
return $denormalized;
}
return $normalizer->denormalize($data, $type, $format, $context);
}