Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[FrameworkBundle] Register the ArrayDenormalizer #20480

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
[FrameworkBundle] Register the ArrayDenormalizer
  • Loading branch information
dunglas committed Nov 10, 2016
commit a190f6139ac31f2ef8f114262a4d8d3dd0558e7e
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,15 @@
<argument type="service" id="serializer.property_accessor" />
<argument type="service" id="property_info" on-invalid="ignore" />

<!-- Run after all custom serializers -->
<!-- Run after all custom normalizers -->
<tag name="serializer.normalizer" priority="-1000" />
</service>

<service id="serializer.denormalizer.array" class="Symfony\Component\Serializer\Normalizer\ArrayDenormalizer" public="false">
<!-- Run before the object normalizer -->
<tag name="serializer.normalizer" priority="-990" />
</service>

<!-- Loader -->
<service id="serializer.mapping.chain_loader" class="Symfony\Component\Serializer\Mapping\Loader\LoaderChain" public="false">
<argument type="collection" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Bundle\FrameworkBundle\Tests\Functional;

/**
* @author Kévin Dunglas <dunglas@gmail.com>
*/
class SerializerTest extends WebTestCase
{
public function testDeserializeArrayOfObject()
{
static::bootKernel(array('test_case' => 'Serializer'));
$container = static::$kernel->getContainer();

$result = $container->get('serializer')->deserialize('{"bars": [{"id": 1}, {"id": 2}]}', Foo::class, 'json');

$bar1 = new Bar();
$bar1->id = 1;
$bar2 = new Bar();
$bar2->id = 2;

$expected = new Foo();
$expected->bars = array($bar1, $bar2);

$this->assertEquals($expected, $result);
}
}

class Foo
{
/**
* @var Bar[]
*/
public $bars;
}

class Bar
{
/**
* @var int
*/
public $id;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

use Symfony\Bundle\FrameworkBundle\FrameworkBundle;

return array(
new FrameworkBundle(),
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
imports:
- { resource: ../config/default.yml }

framework:
serializer: { enabled: true }
property_info: { enabled: true }
Morty Proxy This is a proxified and sanitized view of the page, visit original site.