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

[Serializer] Remove normalizer cache in Serializer class #17140

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

Merged
merged 1 commit into from
Jan 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 0 additions & 2 deletions 2 src/Symfony/Component/Serializer/Serializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,6 @@ private function normalizeObject($object, $format = null, array $context = array
foreach ($this->normalizers as $normalizer) {
if ($normalizer instanceof NormalizerInterface
&& $normalizer->supportsNormalization($object, $format)) {
$this->normalizerCache[$class][$format] = $normalizer;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

those properties should be annotated with @deprecated

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was planning to do a PR to master to deprecate them after this one is merged.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. 👍

return $normalizer->normalize($object, $format, $context);
}
Expand Down Expand Up @@ -272,7 +271,6 @@ private function denormalizeObject($data, $class, $format = null, array $context
foreach ($this->normalizers as $normalizer) {
if ($normalizer instanceof DenormalizerInterface
&& $normalizer->supportsDenormalization($data, $class, $format)) {
$this->denormalizerCache[$class][$format] = $normalizer;

return $normalizer->denormalize($data, $class, $format, $context);
}
Expand Down
44 changes: 44 additions & 0 deletions 44 src/Symfony/Component/Serializer/Tests/SerializerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,50 @@ public function testDenormalizeOnNormalizer()
$this->assertTrue($this->serializer->denormalize(json_encode($data), 'stdClass', 'json'));
}

public function testNormalizeWithSupportOnData()
{
$normalizer1 = $this->getMock('Symfony\Component\Serializer\Normalizer\NormalizerInterface');
$normalizer1->method('supportsNormalization')
->willReturnCallback(function ($data, $format) {
return isset($data->test);
});
$normalizer1->method('normalize')->willReturn('test1');

$normalizer2 = $this->getMock('Symfony\Component\Serializer\Normalizer\NormalizerInterface');
$normalizer2->method('supportsNormalization')
->willReturn(true);
$normalizer2->method('normalize')->willReturn('test2');

$serializer = new Serializer(array($normalizer1, $normalizer2));

$data = new \stdClass();
$data->test = true;
$this->assertEquals('test1', $serializer->normalize($data));

$this->assertEquals('test2', $serializer->normalize(new \stdClass()));
}

public function testDenormalizeWithSupportOnData()
{
$denormalizer1 = $this->getMock('Symfony\Component\Serializer\Normalizer\DenormalizerInterface');
$denormalizer1->method('supportsDenormalization')
->willReturnCallback(function ($data, $type, $format) {
return isset($data['test1']);
});
$denormalizer1->method('denormalize')->willReturn('test1');

$denormalizer2 = $this->getMock('Symfony\Component\Serializer\Normalizer\DenormalizerInterface');
$denormalizer2->method('supportsDenormalization')
->willReturn(true);
$denormalizer2->method('denormalize')->willReturn('test2');

$serializer = new Serializer(array($denormalizer1, $denormalizer2));

$this->assertEquals('test1', $serializer->denormalize(array('test1' => true), 'test'));

$this->assertEquals('test2', $serializer->denormalize(array(), 'test'));
}

public function testSerialize()
{
$this->serializer = new Serializer(array(new GetSetMethodNormalizer()), array('json' => new JsonEncoder()));
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.