private function validateAndDenormalize(array
$types, string
$currentClass, string
$attribute, mixed
$data, ?string
$format, array
$context): mixed
{ $expectedTypes =
[];
$isUnionType = \
count($types) > 1;
$extraAttributesException = null;
$missingConstructorArgumentsException = null;
foreach ($types as $type) { if (null ===
$data &&
$type->
isNullable()) { return null;
} $collectionValueType =
$type->
isCollection() ?
$type->
getCollectionValueTypes()[0
] ?? null : null;
// Fix a collection that contains the only one element
// This is special to xml format only
if ('xml' ===
$format && null !==
$collectionValueType && (!\
is_array($data) || !\
is_int(key($data)))) { $data =
[$data];
} // This try-catch should cover all NotNormalizableValueException (and all return branches after the first
// exception) so we could try denormalizing all types of an union type. If the target type is not an union
// type, we will just re-throw the catched exception.
// In the case of no denormalization succeeds with an union type, it will fall back to the default exception