Skip to content

Commit 38b1529

Browse files
committed
Merge branch '2.8' into 3.0
* 2.8: Updated all the README files [TwigBundle] Fix failing test on appveyor Improved the error message when using "@" in a decorated service Improve error reporting in router panel of web profiler [DoctrineBridge][Form] Fix performance regression in EntityType [FrameworkBundle] Fix a regression in handling absolute and namespaced template paths Allow to normalize \Traversable minor [Form] fix tests added by #16886 Remove _path from query parameters when fragment is a subrequest and request attributes are already set Added tests for _path removal in FragmentListener Simplified everything Added a test Fixed the problem in an easier way Fixed a syntax issue Improved the error message when a template is not found [CodingStandards] Conformed to coding standards [TwigBundle] fixed Include file locations in "Template could not be found" exception
2 parents 7ee03c1 + 86d5c68 commit 38b1529

File tree

3 files changed

+26
-9
lines changed

3 files changed

+26
-9
lines changed

Encoder/XmlEncoder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ private function buildXml(\DOMNode $parentNode, $data, $xmlRootNodeName = null)
366366
{
367367
$append = true;
368368

369-
if (is_array($data) || $data instanceof \Traversable) {
369+
if (is_array($data) || ($data instanceof \Traversable && !$this->serializer->supportsNormalization($data, $this->format))) {
370370
foreach ($data as $key => $data) {
371371
//Ah this is the magic @ attribute types.
372372
if (0 === strpos($key, '@') && is_scalar($data) && $this->isElementNameValid($attributeName = substr($key, 1))) {

README.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
Serializer Component
22
====================
33

4-
With the Serializer component it's possible to handle serializing data structures,
5-
including object graphs, into array structures or other formats like XML and JSON.
6-
It can also handle deserializing XML and JSON back to object graphs.
4+
With the Serializer component it's possible to handle serializing data
5+
structures, including object graphs, into array structures or other formats like
6+
XML and JSON. It can also handle deserializing XML and JSON back to object
7+
graphs.
78

89
Resources
910
---------
1011

11-
You can run the unit tests with the following command:
12-
13-
$ cd path/to/Symfony/Component/Serializer/
14-
$ composer install
15-
$ phpunit
12+
* [Documentation](https://symfony.com/doc/current/components/serializer.html)
13+
* [Contributing](https://symfony.com/doc/current/contributing/index.html)
14+
* [Report issues](https://github.com/symfony/symfony/issues) and
15+
[send Pull Requests](https://github.com/symfony/symfony/pulls)
16+
in the [main Symfony repository](https://github.com/symfony/symfony)

Tests/Encoder/XmlEncoderTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Serializer\Tests\Encoder;
1313

1414
use Symfony\Component\Serializer\Tests\Fixtures\Dummy;
15+
use Symfony\Component\Serializer\Tests\Fixtures\NormalizableTraversableDummy;
1516
use Symfony\Component\Serializer\Tests\Fixtures\ScalarDummy;
1617
use Symfony\Component\Serializer\Encoder\XmlEncoder;
1718
use Symfony\Component\Serializer\Serializer;
@@ -248,6 +249,21 @@ public function testEncodeSerializerXmlRootNodeNameOption()
248249
$this->assertEquals($expected, $serializer->serialize($array, 'xml', $options));
249250
}
250251

252+
public function testEncodeTraversableWhenNormalizable() {
253+
$this->encoder = new XmlEncoder();
254+
$serializer = new Serializer(array(new CustomNormalizer()), array('xml' => new XmlEncoder()));
255+
$this->encoder->setSerializer($serializer);
256+
257+
$expected = <<<XML
258+
<?xml version="1.0"?>
259+
<response><foo>normalizedFoo</foo><bar>normalizedBar</bar></response>
260+
261+
XML;
262+
263+
$this->assertEquals($expected, $serializer->serialize(new NormalizableTraversableDummy(), 'xml'));
264+
265+
}
266+
251267
public function testDecode()
252268
{
253269
$source = $this->getXmlSource();

0 commit comments

Comments
 (0)