Open mabar opened 1 year ago
jms/serializer has Xml* attributes for that - see https://jmsyst.com/libs/serializer/master/reference/annotations
use JMS\Serializer\Annotation\XmlAttribute;
use JMS\Serializer\Annotation\XmlValue;
use JMS\Serializer\Annotation\XmlRoot;
/** @XmlRoot("price") */
class Price
{
/** @XmlAttribute */
private $currency = 'EUR';
/** @XmlValue */
private $amount = 1.23;
}
XmlValue should probably be default
symfony/serializer does something similar too, but the exact format should be mainly declared by the object and not in global config https://symfony.com/doc/current/components/serializer.html#the-xmlencoder
For now I removed support for stdClass from processor. Proper support for various formats will be implemented later https://github.com/orisai/object-mapper/commit/5edbc1adbf93cd1794cea90c1f2b2a61ae929ab0
TIL that any stdClass
in $data
will cause validation to fail. But it will not tell you where it failed.
Most like this to blame: https://github.com/orisai/object-mapper/blob/e974721d8c8d6008ae811c107bd8e7db942fe2fa/src/Processing/DefaultProcessor.php#L220
I might add a test case for this and we might also want to add error to type when this happens. https://github.com/orisai/object-mapper/blob/e974721d8c8d6008ae811c107bd8e7db942fe2fa/src/Processing/DefaultProcessor.php#L224
Description
Currently if processor is given an output from
json_decode($value)
, anstdClass
is casted toarray
in case it's in place of aMappedObjectValue
. ButstdClass
makes sense to handle also in case of anArrayOf
and aListOf
.Handling should be also available in
Value
in case printer decides to print an invalid value.We should also consider that fix on user side is as simple as
json_decode($value, true)
and that it may work only for some formats:stdClass
and adds an extra properties.SimpleXMLElement
and we have no way of casting it to an array, handling attributes or printing errors while maintaining the original xml structureAddition information
No response
Related issues
No response