8000 [Serializer] Xml encoder throws exception for valid data · Issue #21617 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
[Serializer] Xml encoder throws exception for valid data #21617
Closed
@gr1ev0us

Description

@gr1ev0us
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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0