Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/Serializer/AbstractItemNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -399,11 +399,13 @@
return $class;
}

if (!isset($data[$mapping->getTypeProperty()])) {
// @phpstan-ignore-next-line function.alreadyNarrowedType
$defaultType = method_exists($mapping, 'getDefaultType') ? $mapping->getDefaultType() : null;
if (!isset($data[$mapping->getTypeProperty()]) && null === $defaultType) {

Check warning on line 404 in src/Serializer/AbstractItemNormalizer.php

View check run for this annotation

Codecov / codecov/patch

src/Serializer/AbstractItemNormalizer.php#L403-L404

Added lines #L403 - L404 were not covered by tests
throw NotNormalizableValueException::createForUnexpectedDataType(\sprintf('Type property "%s" not found for the abstract object "%s".', $mapping->getTypeProperty(), $class), null, ['string'], isset($context['deserialization_path']) ? $context['deserialization_path'].'.'.$mapping->getTypeProperty() : $mapping->getTypeProperty());
}

$type = $data[$mapping->getTypeProperty()];
$type = $data[$mapping->getTypeProperty()] ?? $defaultType;

Check warning on line 408 in src/Serializer/AbstractItemNormalizer.php

View check run for this annotation

Codecov / codecov/patch

src/Serializer/AbstractItemNormalizer.php#L408

Added line #L408 was not covered by tests
if (null === ($mappedClass = $mapping->getClassForType($type))) {
throw NotNormalizableValueException::createForUnexpectedDataType(\sprintf('The type "%s" is not a valid value.', $type), $type, ['string'], isset($context['deserialization_path']) ? $context['deserialization_path'].'.'.$mapping->getTypeProperty() : $mapping->getTypeProperty(), true);
}
Expand Down
Loading