Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit98561d4

Browse files
committed
Do not cache cache attributes ifattributes is in the context
1 parentb568e16 commit98561d4

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

‎src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ protected function getAttributes($object, $format = null, array $context)
126126
return$allowedAttributes;
127127
}
128128

129-
if (isset($this->attributesCache[$class])) {
129+
if (isset($this->attributesCache[$class]) && !isset($context['attributes'])) {
130130
return$this->attributesCache[$class];
131131
}
132132

‎src/Symfony/Component/Serializer/Tests/Normalizer/ObjectNormalizerTest.php‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,37 @@ public function testAttributesContextDenormalizeConstructor()
713713
'inner' =>array('foo' =>'foo','bar' =>'bar'),
714714
), DummyWithConstructorObjectAndDefaultValue::class,null,$context));
715715
}
716+
717+
publicfunctiontestNormalizeSameObjectWithDifferentAttributes()
718+
{
719+
$classMetadataFactory =newClassMetadataFactory(newAnnotationLoader(newAnnotationReader()));
720+
$this->normalizer =newObjectNormalizer($classMetadataFactory);
721+
$serializer =newSerializer(array($this->normalizer));
722+
$this->normalizer->setSerializer($serializer);
723+
724+
$dummy =newObjectOuter();
725+
$dummy->foo =newObjectInner();
726+
$dummy->foo->foo ='foo.foo';
727+
$dummy->foo->bar ='foo.bar';
728+
729+
$dummy->bar =newObjectInner();
730+
$dummy->bar->foo ='bar.foo';
731+
$dummy->bar->bar ='bar.bar';
732+
733+
$this->assertEquals(array(
734+
'foo' =>array(
735+
'bar' =>'foo.bar',
736+
),
737+
'bar' =>array(
738+
'foo' =>'bar.foo',
739+
)
740+
),$this->normalizer->normalize($dummy,'json',array(
741+
'attributes' =>array(
742+
'foo' =>array('bar'),
743+
'bar' =>array('foo')
744+
)
745+
)));
746+
}
716747
}
717748

718749
class ObjectDummy

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp