Closed
Description
Q | A |
---|---|
Bug report? | yes |
Feature request? | no |
BC Break report? | no |
RFC? | no |
Symfony version | 2.7.x |
The problem is in a xml serialization array/object contained DateTime object. To normalize this i am using DateTimeNormalizer (it appeared in sf 3.2, but in my project I use my custom implementation). As a result I get an UnexpectedValueException.
How to reproduce a bug:
use Symfony\Component\Serializer\Serializer;
use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
use Symfony\Component\Serializer\Encoder\XmlEncoder;
$serializer = (new Serializer([new DateTimeNormalizer, new XmlEncoder]));
$result = $serializer->serialize(['node'=> new DateTime('2017-02-13T17:54:23+0300')]);
expects:
<response><node>2017-02-13T17:54:23+0300</node></response>
actual: An unexpected value could not be serialized: '2017-02-13T17:54:23+0300'
I suppose, there is no need to normalize value before buildXml invocation:
https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Serializer/Encoder/XmlEncoder.php#L480