// 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
// with the acceptable types list.
try { // In XML and CSV all basic datatypes are represented as strings, it is e.g. not possible to determine,
// if a value is meant to be a string, float, int or a boolean value from the serialized representation.
// That's why we have to transform the values, if one of these non-string basic datatypes is expected.
if (\
is_string($data) && (XmlEncoder::FORMAT ===
$format || CsvEncoder::FORMAT ===
$format)) { if ('' ===
$data) { if (Type::BUILTIN_TYPE_ARRAY ===
$builtinType =
$type->
getBuiltinType()) { return [];
} if ($type->
isNullable() && \
in_array($builtinType,
[Type::BUILTIN_TYPE_BOOL, Type::BUILTIN_TYPE_INT, Type::BUILTIN_TYPE_FLOAT
], true
)) { return null;
} } switch ($builtinType ??
$type->
getBuiltinType()) { case Type::BUILTIN_TYPE_BOOL:
// according to https://www.w3.org/TR/xmlschema-2/#boolean, valid representations are "false", "true", "0" and "1"