You signed in with another tab or window.Reload to refresh your session.You signed out in another tab or window.Reload to refresh your session.You switched accounts on another tab or window.Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/CHANGELOG.md
+1Lines changed: 1 addition & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -12,6 +12,7 @@ CHANGELOG
12
12
* Change the signature of`ClassMetadataInterface::setClassDiscriminatorMapping()` to`setClassDiscriminatorMapping(?ClassDiscriminatorMapping)`
13
13
* Add option YamlEncoder::YAML_INDENTATION to YamlEncoder constructor options to configure additional indentation for each level of nesting. This allows configuring indentation in the service configuration.
14
14
* Add`SerializedPath` annotation to flatten nested attributes
15
+
* Add`PropertyValueNormalizer` to`AbstractObjectNormalizer` to enabled code reusability in custom`ObjectNormalizer`
// Fix a collection that contains the only one element
437
-
// This is special to xml format only
438
-
if ('xml' ===$format &&null !==$collectionValueType && (!\is_array($data) || !\is_int(key($data)))) {
439
-
$data = [$data];
440
-
}
441
-
442
-
// This try-catch should cover all NotNormalizableValueException (and all return branches after the first
443
-
// exception) so we could try denormalizing all types of an union type. If the target type is not an union
444
-
// type, we will just re-throw the catched exception.
445
-
// In the case of no denormalization succeeds with an union type, it will fall back to the default exception
446
-
// with the acceptable types list.
447
-
try {
448
-
// In XML and CSV all basic datatypes are represented as strings, it is e.g. not possible to determine,
449
-
// if a value is meant to be a string, float, int or a boolean value from the serialized representation.
450
-
// That's why we have to transform the values, if one of these non-string basic datatypes is expected.
451
-
if (\is_string($data) && (XmlEncoder::FORMAT ===$format || CsvEncoder::FORMAT ===$format)) {
452
-
if ('' ===$data) {
453
-
if (Type::BUILTIN_TYPE_ARRAY ===$builtinType =$type->getBuiltinType()) {
454
-
return [];
455
-
}
456
-
457
-
if ($type->isNullable() &&\in_array($builtinType, [Type::BUILTIN_TYPE_BOOL, Type::BUILTIN_TYPE_INT, Type::BUILTIN_TYPE_FLOAT],true)) {
458
-
returnnull;
459
-
}
460
-
}
461
-
462
-
switch ($builtinType ??$type->getBuiltinType()) {
463
-
case Type::BUILTIN_TYPE_BOOL:
464
-
// according to https://www.w3.org/TR/xmlschema-2/#boolean, valid representations are "false", "true", "0" and "1"
465
-
if ('false' ===$data ||'0' ===$data) {
466
-
$data =false;
467
-
}elseif ('true' ===$data ||'1' ===$data) {
468
-
$data =true;
469
-
}else {
470
-
throw NotNormalizableValueException::createForUnexpectedDataType(sprintf('The type of the "%s" attribute for class "%s" must be bool ("%s" given).',$attribute,$currentClass,$data),$data, [Type::BUILTIN_TYPE_BOOL],$context['deserialization_path'] ??null);
471
-
}
472
-
break;
473
-
case Type::BUILTIN_TYPE_INT:
474
-
if (ctype_digit('-' ===$data[0] ?substr($data,1) :$data)) {
475
-
$data = (int)$data;
476
-
}else {
477
-
throw NotNormalizableValueException::createForUnexpectedDataType(sprintf('The type of the "%s" attribute for class "%s" must be int ("%s" given).',$attribute,$currentClass,$data),$data, [Type::BUILTIN_TYPE_INT],$context['deserialization_path'] ??null);
478
-
}
479
-
break;
480
-
case Type::BUILTIN_TYPE_FLOAT:
481
-
if (is_numeric($data)) {
482
-
return (float)$data;
483
-
}
484
-
485
-
returnmatch ($data) {
486
-
'NaN' => \NAN,
487
-
'INF' => \INF,
488
-
'-INF' => -\INF,
489
-
default =>throw NotNormalizableValueException::createForUnexpectedDataType(sprintf('The type of the "%s" attribute for class "%s" must be float ("%s" given).',$attribute,$currentClass,$data),$data, [Type::BUILTIN_TYPE_FLOAT],$context['deserialization_path'] ??null),
490
-
};
491
-
}
492
-
}
493
-
494
-
if (null !==$collectionValueType && Type::BUILTIN_TYPE_OBJECT ===$collectionValueType->getBuiltinType()) {
if (!$this->serializerinstanceof DenormalizerInterface) {
532
-
thrownewLogicException(sprintf('Cannot denormalize attribute "%s" for class "%s" because injected serializer is not a denormalizer.',$attribute,$class));
if ($context[self::DISABLE_TYPE_ENFORCEMENT] ??$this->defaultContext[self::DISABLE_TYPE_ENFORCEMENT] ??false) {
586
-
return$data;
587
-
}
588
-
589
-
throw NotNormalizableValueException::createForUnexpectedDataType(sprintf('The type of the "%s" attribute for class "%s" must be one of "%s" ("%s" given).',$attribute,$currentClass,implode('", "',array_keys($expectedTypes)),get_debug_type($data)),$data,array_keys($expectedTypes),$context['deserialization_path'] ??$attribute);