Description
Symfony version(s) affected
6.4.x
Description
have a xml representation like this:
<cac:CommodityClassification>
<cbc:ItemClassificationCode listID="IB" listVersionID="88">0721-880X</cbc:ItemClassificationCode>
</cac:CommodityClassification>
ItemClassificationCode is represented by this class
class CodeType
{
public function __construct(
#[SerializedName('#')]
public string $value,
#[SerializedName('@listID')]
public ?string $listID = null,
#[SerializedName('@listAgencyID')]
public ?string $listAgencyID = null,
#[SerializedName('@listAgencyName')]
public ?string $listAgencyName = null,
#[SerializedName('@listName')]
public ?string $listName = null,
#[SerializedName('@listVersionID')]
public ?string $listVersionID = null,
#[SerializedName('@name')]
public ?string $name = null,
#[SerializedName('@languageID')]
public ?string $languageID = null,
#[SerializedName('@listURI')]
public ?string $listURI = null,
#[SerializedName('@listSchemeURI')]
public ?string $listSchemeURI = null
)
{}
}
See that the type of listVersionID
should be a string?
Now XmlEncoder assumes on decoding that the attribute could be an int:
symfony/src/Symfony/Component/Serializer/Encoder/XmlEncoder.php
Lines 273 to 277 in 6864dbe
which then causes a crash in AbstractObjectNormalizer:
Symfony\Component\Serializer\Exception\NotNormalizableValueException: The type of the "listVersionID" attribute for class "UBL\UnqualifiedDataTypes\CodeType" must be one of "string" ("int" given).
There is a special case for reading string and turning it into float and other values.
But there is no case where it should be string instead
How to reproduce
use this example xml:
<cac:CommodityClassification>
<cbc:ItemClassificationCode listID="IB" listVersionID="88">0721-880X</cbc:ItemClassificationCode>
</cac:CommodityClassification>
Possible Solution
No response
Additional Context
No response