4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Serializer\Tests\Normalizer;
14 use Doctrine\Common\Annotations\AnnotationReader;
15 use PHPUnit\Framework\TestCase;
16 use Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor;
17 use Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor;
18 use Symfony\Component\PropertyInfo\PropertyInfoExtractor;
19 use Symfony\Component\Serializer\NameConverter\CamelCaseToSnakeCaseNameConverter;
20 use Symfony\Component\Serializer\Normalizer\ArrayDenormalizer;
21 use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
22 use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
23 use Symfony\Component\Serializer\Serializer;
24 use Symfony\Component\Serializer\SerializerInterface;
25 use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
26 use Symfony\Component\Serializer\Tests\Fixtures\CircularReferenceDummy;
27 use Symfony\Component\Serializer\Tests\Fixtures\MaxDepthDummy;
28 use Symfony\Component\Serializer\Tests\Fixtures\SiblingHolder;
29 use Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader;
30 use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory;
31 use Symfony\Component\Serializer\Tests\Fixtures\GroupDummy;
34 * @author Kévin Dunglas <dunglas@gmail.com>
36 class ObjectNormalizerTest extends TestCase
39 * @var ObjectNormalizer
43 * @var SerializerInterface
47 protected function setUp()
49 $this->serializer = $this->getMockBuilder(__NAMESPACE__.'\ObjectSerializerNormalizer')->getMock();
50 $this->normalizer = new ObjectNormalizer();
51 $this->normalizer->setSerializer($this->serializer);
54 public function testNormalize()
56 $obj = new ObjectDummy();
57 $object = new \stdClass();
61 $obj->setCamelCase('camelcase');
62 $obj->setObject($object);
65 ->expects($this->once())
67 ->with($object, 'any')
68 ->will($this->returnValue('string_object'))
77 'camelCase' => 'camelcase',
78 'object' => 'string_object',
80 $this->normalizer->normalize($obj, 'any')
84 public function testDenormalize()
86 $obj = $this->normalizer->denormalize(
87 array('foo' => 'foo', 'bar' => 'bar', 'baz' => true, 'fooBar' => 'foobar'),
88 __NAMESPACE__.'\ObjectDummy',
91 $this->assertEquals('foo', $obj->getFoo());
92 $this->assertEquals('bar', $obj->bar);
93 $this->assertTrue($obj->isBaz());
96 public function testDenormalizeWithObject()
98 $data = new \stdClass();
101 $data->fooBar = 'foobar';
102 $obj = $this->normalizer->denormalize($data, __NAMESPACE__.'\ObjectDummy', 'any');
103 $this->assertEquals('foo', $obj->getFoo());
104 $this->assertEquals('bar', $obj->bar);
107 public function testDenormalizeNull()
109 $this->assertEquals(new ObjectDummy(), $this->normalizer->denormalize(null, __NAMESPACE__.'\ObjectDummy'));
112 public function testConstructorDenormalize()
114 $obj = $this->normalizer->denormalize(
115 array('foo' => 'foo', 'bar' => 'bar', 'baz' => true, 'fooBar' => 'foobar'),
116 __NAMESPACE__.'\ObjectConstructorDummy', 'any');
117 $this->assertEquals('foo', $obj->getFoo());
118 $this->assertEquals('bar', $obj->bar);
119 $this->assertTrue($obj->isBaz());
122 public function testConstructorDenormalizeWithNullArgument()
124 $obj = $this->normalizer->denormalize(
125 array('foo' => 'foo', 'bar' => null, 'baz' => true),
126 __NAMESPACE__.'\ObjectConstructorDummy', 'any');
127 $this->assertEquals('foo', $obj->getFoo());
128 $this->assertNull($obj->bar);
129 $this->assertTrue($obj->isBaz());
132 public function testConstructorDenormalizeWithMissingOptionalArgument()
134 $obj = $this->normalizer->denormalize(
135 array('foo' => 'test', 'baz' => array(1, 2, 3)),
136 __NAMESPACE__.'\ObjectConstructorOptionalArgsDummy', 'any');
137 $this->assertEquals('test', $obj->getFoo());
138 $this->assertEquals(array(), $obj->bar);
139 $this->assertEquals(array(1, 2, 3), $obj->getBaz());
142 public function testConstructorDenormalizeWithOptionalDefaultArgument()
144 $obj = $this->normalizer->denormalize(
145 array('bar' => 'test'),
146 __NAMESPACE__.'\ObjectConstructorArgsWithDefaultValueDummy', 'any');
147 $this->assertEquals(array(), $obj->getFoo());
148 $this->assertEquals('test', $obj->getBar());
151 public function testConstructorWithObjectDenormalize()
153 $data = new \stdClass();
157 $data->fooBar = 'foobar';
158 $obj = $this->normalizer->denormalize($data, __NAMESPACE__.'\ObjectConstructorDummy', 'any');
159 $this->assertEquals('foo', $obj->getFoo());
160 $this->assertEquals('bar', $obj->bar);
163 public function testConstructorWithObjectTypeHintDenormalize()
173 $normalizer = new ObjectNormalizer();
174 $serializer = new Serializer(array($normalizer));
175 $normalizer->setSerializer($serializer);
177 $obj = $normalizer->denormalize($data, DummyWithConstructorObject::class);
178 $this->assertInstanceOf(DummyWithConstructorObject::class, $obj);
179 $this->assertEquals(10, $obj->getId());
180 $this->assertInstanceOf(ObjectInner::class, $obj->getInner());
181 $this->assertEquals('oof', $obj->getInner()->foo);
182 $this->assertEquals('rab', $obj->getInner()->bar);
186 * @expectedException \Symfony\Component\Serializer\Exception\RuntimeException
187 * @expectedExceptionMessage Could not determine the class of the parameter "unknown".
189 public function testConstructorWithUnknownObjectTypeHintDenormalize()
199 $normalizer = new ObjectNormalizer();
200 $serializer = new Serializer(array($normalizer));
201 $normalizer->setSerializer($serializer);
203 $normalizer->denormalize($data, DummyWithConstructorInexistingObject::class);
206 public function testGroupsNormalize()
208 $classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
209 $this->normalizer = new ObjectNormalizer($classMetadataFactory);
210 $this->normalizer->setSerializer($this->serializer);
212 $obj = new GroupDummy();
215 $obj->setFooBar('fooBar');
216 $obj->setSymfony('symfony');
217 $obj->setKevin('kevin');
218 $obj->setCoopTilleuls('coopTilleuls');
220 $this->assertEquals(array(
222 ), $this->normalizer->normalize($obj, null, array(ObjectNormalizer::GROUPS => array('c'))));
224 $this->assertEquals(array(
225 'symfony' => 'symfony',
227 'fooBar' => 'fooBar',
230 'coopTilleuls' => 'coopTilleuls',
231 ), $this->normalizer->normalize($obj, null, array(ObjectNormalizer::GROUPS => array('a', 'c'))));
234 public function testGroupsDenormalize()
236 $classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
237 $this->normalizer = new ObjectNormalizer($classMetadataFactory);
238 $this->normalizer->setSerializer($this->serializer);
240 $obj = new GroupDummy();
243 $toNormalize = array('foo' => 'foo', 'bar' => 'bar');
245 $normalized = $this->normalizer->denormalize(
247 'Symfony\Component\Serializer\Tests\Fixtures\GroupDummy',
249 array(ObjectNormalizer::GROUPS => array('a'))
251 $this->assertEquals($obj, $normalized);
255 $normalized = $this->normalizer->denormalize(
257 'Symfony\Component\Serializer\Tests\Fixtures\GroupDummy',
259 array(ObjectNormalizer::GROUPS => array('a', 'b'))
261 $this->assertEquals($obj, $normalized);
264 public function testNormalizeNoPropertyInGroup()
266 $classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
267 $this->normalizer = new ObjectNormalizer($classMetadataFactory);
268 $this->normalizer->setSerializer($this->serializer);
270 $obj = new GroupDummy();
273 $this->assertEquals(array(), $this->normalizer->normalize($obj, null, array('groups' => array('notExist'))));
276 public function testGroupsNormalizeWithNameConverter()
278 $classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
279 $this->normalizer = new ObjectNormalizer($classMetadataFactory, new CamelCaseToSnakeCaseNameConverter());
280 $this->normalizer->setSerializer($this->serializer);
282 $obj = new GroupDummy();
283 $obj->setFooBar('@dunglas');
284 $obj->setSymfony('@coopTilleuls');
285 $obj->setCoopTilleuls('les-tilleuls.coop');
290 'foo_bar' => '@dunglas',
291 'symfony' => '@coopTilleuls',
293 $this->normalizer->normalize($obj, null, array(ObjectNormalizer::GROUPS => array('name_converter')))
297 public function testGroupsDenormalizeWithNameConverter()
299 $classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
300 $this->normalizer = new ObjectNormalizer($classMetadataFactory, new CamelCaseToSnakeCaseNameConverter());
301 $this->normalizer->setSerializer($this->serializer);
303 $obj = new GroupDummy();
304 $obj->setFooBar('@dunglas');
305 $obj->setSymfony('@coopTilleuls');
309 $this->normalizer->denormalize(array(
311 'foo_bar' => '@dunglas',
312 'symfony' => '@coopTilleuls',
313 'coop_tilleuls' => 'les-tilleuls.coop',
314 ), 'Symfony\Component\Serializer\Tests\Fixtures\GroupDummy', null, array(ObjectNormalizer::GROUPS => array('name_converter')))
319 * @dataProvider provideCallbacks
321 public function testCallbacks($callbacks, $value, $result, $message)
323 $this->normalizer->setCallbacks($callbacks);
325 $obj = new ObjectConstructorDummy('', $value, true);
329 $this->normalizer->normalize($obj, 'any'),
335 * @expectedException \InvalidArgumentException
337 public function testUncallableCallbacks()
339 $this->normalizer->setCallbacks(array('bar' => null));
341 $obj = new ObjectConstructorDummy('baz', 'quux', true);
343 $this->normalizer->normalize($obj, 'any');
346 public function testIgnoredAttributes()
348 $this->normalizer->setIgnoredAttributes(array('foo', 'bar', 'baz', 'camelCase', 'object'));
350 $obj = new ObjectDummy();
356 array('fooBar' => 'foobar'),
357 $this->normalizer->normalize($obj, 'any')
361 public function testIgnoredAttributesDenormalize()
363 $this->normalizer->setIgnoredAttributes(array('fooBar', 'bar', 'baz'));
365 $obj = new ObjectDummy();
370 $this->normalizer->denormalize(array('fooBar' => 'fooBar', 'foo' => 'foo', 'baz' => 'baz'), __NAMESPACE__.'\ObjectDummy')
374 public function provideCallbacks()
379 'bar' => function ($bar) {
384 array('foo' => '', 'bar' => 'baz', 'baz' => true),
389 'bar' => function ($bar) {
394 array('foo' => '', 'bar' => null, 'baz' => true),
399 'bar' => function ($bar) {
400 return $bar->format('d-m-Y H:i:s');
403 new \DateTime('2011-09-10 06:30:00'),
404 array('foo' => '', 'bar' => '10-09-2011 06:30:00', 'baz' => true),
409 'bar' => function ($bars) {
411 foreach ($bars as $bar) {
412 $foos .= $bar->getFoo();
418 array(new ObjectConstructorDummy('baz', '', false), new ObjectConstructorDummy('quux', '', false)),
419 array('foo' => '', 'bar' => 'bazquux', 'baz' => true),
420 'Collect a property',
424 'bar' => function ($bars) {
428 array(new ObjectConstructorDummy('baz', '', false), new ObjectConstructorDummy('quux', '', false)),
429 array('foo' => '', 'bar' => 2, 'baz' => true),
436 * @expectedException \Symfony\Component\Serializer\Exception\LogicException
437 * @expectedExceptionMessage Cannot normalize attribute "object" because the injected serializer is not a normalizer
439 public function testUnableToNormalizeObjectAttribute()
441 $serializer = $this->getMockBuilder('Symfony\Component\Serializer\SerializerInterface')->getMock();
442 $this->normalizer->setSerializer($serializer);
444 $obj = new ObjectDummy();
445 $object = new \stdClass();
446 $obj->setObject($object);
448 $this->normalizer->normalize($obj, 'any');
452 * @expectedException \Symfony\Component\Serializer\Exception\CircularReferenceException
454 public function testUnableToNormalizeCircularReference()
456 $serializer = new Serializer(array($this->normalizer));
457 $this->normalizer->setSerializer($serializer);
458 $this->normalizer->setCircularReferenceLimit(2);
460 $obj = new CircularReferenceDummy();
462 $this->normalizer->normalize($obj);
465 public function testSiblingReference()
467 $serializer = new Serializer(array($this->normalizer));
468 $this->normalizer->setSerializer($serializer);
470 $siblingHolder = new SiblingHolder();
473 'sibling0' => array('coopTilleuls' => 'Les-Tilleuls.coop'),
474 'sibling1' => array('coopTilleuls' => 'Les-Tilleuls.coop'),
475 'sibling2' => array('coopTilleuls' => 'Les-Tilleuls.coop'),
477 $this->assertEquals($expected, $this->normalizer->normalize($siblingHolder));
480 public function testCircularReferenceHandler()
482 $serializer = new Serializer(array($this->normalizer));
483 $this->normalizer->setSerializer($serializer);
484 $this->normalizer->setCircularReferenceHandler(function ($obj) {
485 return get_class($obj);
488 $obj = new CircularReferenceDummy();
490 $expected = array('me' => 'Symfony\Component\Serializer\Tests\Fixtures\CircularReferenceDummy');
491 $this->assertEquals($expected, $this->normalizer->normalize($obj));
494 public function testDenormalizeNonExistingAttribute()
498 $this->normalizer->denormalize(array('non_existing' => true), __NAMESPACE__.'\ObjectDummy')
502 public function testNoTraversableSupport()
504 $this->assertFalse($this->normalizer->supportsNormalization(new \ArrayObject()));
507 public function testNormalizeStatic()
509 $this->assertEquals(array('foo' => 'K'), $this->normalizer->normalize(new ObjectWithStaticPropertiesAndMethods()));
512 public function testNormalizeUpperCaseAttributes()
514 $this->assertEquals(array('Foo' => 'Foo', 'Bar' => 'BarBar'), $this->normalizer->normalize(new ObjectWithUpperCaseAttributeNames()));
517 public function testNormalizeNotSerializableContext()
519 $objectDummy = new ObjectDummy();
529 $this->assertEquals($expected, $this->normalizer->normalize($objectDummy, null, array('not_serializable' => function () {
533 public function testMaxDepth()
535 $classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
536 $this->normalizer = new ObjectNormalizer($classMetadataFactory);
537 $serializer = new Serializer(array($this->normalizer));
538 $this->normalizer->setSerializer($serializer);
540 $level1 = new MaxDepthDummy();
541 $level1->foo = 'level1';
543 $level2 = new MaxDepthDummy();
544 $level2->foo = 'level2';
545 $level1->child = $level2;
547 $level3 = new MaxDepthDummy();
548 $level3->foo = 'level3';
549 $level2->child = $level3;
551 $result = $serializer->normalize($level1, null, array(ObjectNormalizer::ENABLE_MAX_DEPTH => true));
566 $this->assertEquals($expected, $result);
570 * @expectedException \Symfony\Component\Serializer\Exception\UnexpectedValueException
572 public function testThrowUnexpectedValueException()
574 $this->normalizer->denormalize(array('foo' => 'bar'), ObjectTypeHinted::class);
577 public function testDenomalizeRecursive()
579 $extractor = new PropertyInfoExtractor(array(), array(new PhpDocExtractor(), new ReflectionExtractor()));
580 $normalizer = new ObjectNormalizer(null, null, null, $extractor);
581 $serializer = new Serializer(array(new ArrayDenormalizer(), new DateTimeNormalizer(), $normalizer));
583 $obj = $serializer->denormalize(array(
584 'inner' => array('foo' => 'foo', 'bar' => 'bar'),
585 'date' => '1988/01/21',
586 'inners' => array(array('foo' => 1), array('foo' => 2)),
587 ), ObjectOuter::class);
589 $this->assertSame('foo', $obj->getInner()->foo);
590 $this->assertSame('bar', $obj->getInner()->bar);
591 $this->assertSame('1988-01-21', $obj->getDate()->format('Y-m-d'));
592 $this->assertSame(1, $obj->getInners()[0]->foo);
593 $this->assertSame(2, $obj->getInners()[1]->foo);
596 public function testAcceptJsonNumber()
598 $extractor = new PropertyInfoExtractor(array(), array(new PhpDocExtractor(), new ReflectionExtractor()));
599 $normalizer = new ObjectNormalizer(null, null, null, $extractor);
600 $serializer = new Serializer(array(new ArrayDenormalizer(), new DateTimeNormalizer(), $normalizer));
602 $this->assertSame(10.0, $serializer->denormalize(array('number' => 10), JsonNumber::class, 'json')->number);
603 $this->assertSame(10.0, $serializer->denormalize(array('number' => 10), JsonNumber::class, 'jsonld')->number);
607 * @expectedException \Symfony\Component\Serializer\Exception\UnexpectedValueException
608 * @expectedExceptionMessage The type of the "date" attribute for class "Symfony\Component\Serializer\Tests\Normalizer\ObjectOuter" must be one of "DateTimeInterface" ("string" given).
610 public function testRejectInvalidType()
612 $normalizer = new ObjectNormalizer(null, null, null, new ReflectionExtractor());
613 $serializer = new Serializer(array($normalizer));
615 $serializer->denormalize(array('date' => 'foo'), ObjectOuter::class);
619 * @expectedException \Symfony\Component\Serializer\Exception\UnexpectedValueException
620 * @expectedExceptionMessage The type of the key "a" must be "int" ("string" given).
622 public function testRejectInvalidKey()
624 $extractor = new PropertyInfoExtractor(array(), array(new PhpDocExtractor(), new ReflectionExtractor()));
625 $normalizer = new ObjectNormalizer(null, null, null, $extractor);
626 $serializer = new Serializer(array(new ArrayDenormalizer(), new DateTimeNormalizer(), $normalizer));
628 $serializer->denormalize(array('inners' => array('a' => array('foo' => 1))), ObjectOuter::class);
631 public function testDoNotRejectInvalidTypeOnDisableTypeEnforcementContextOption()
633 $extractor = new PropertyInfoExtractor(array(), array(new PhpDocExtractor()));
634 $normalizer = new ObjectNormalizer(null, null, null, $extractor);
635 $serializer = new Serializer(array($normalizer));
636 $context = array(ObjectNormalizer::DISABLE_TYPE_ENFORCEMENT => true);
638 $this->assertSame('foo', $serializer->denormalize(array('number' => 'foo'), JsonNumber::class, null, $context)->number);
641 public function testExtractAttributesRespectsFormat()
643 $normalizer = new FormatAndContextAwareNormalizer();
645 $data = new ObjectDummy();
646 $data->setFoo('bar');
649 $this->assertSame(array('foo' => 'bar', 'bar' => 'foo'), $normalizer->normalize($data, 'foo_and_bar_included'));
652 public function testExtractAttributesRespectsContext()
654 $normalizer = new FormatAndContextAwareNormalizer();
656 $data = new ObjectDummy();
657 $data->setFoo('bar');
660 $this->assertSame(array('foo' => 'bar', 'bar' => 'foo'), $normalizer->normalize($data, null, array('include_foo_and_bar' => true)));
663 public function testAttributesContextNormalize()
665 $normalizer = new ObjectNormalizer();
666 $serializer = new Serializer(array($normalizer));
668 $objectInner = new ObjectInner();
669 $objectInner->foo = 'innerFoo';
670 $objectInner->bar = 'innerBar';
672 $objectDummy = new ObjectDummy();
673 $objectDummy->setFoo('foo');
674 $objectDummy->setBaz(true);
675 $objectDummy->setObject($objectInner);
677 $context = array('attributes' => array('foo', 'baz', 'object' => array('foo')));
682 'object' => array('foo' => 'innerFoo'),
684 $serializer->normalize($objectDummy, null, $context)
687 $context = array('attributes' => array('foo', 'baz', 'object'));
692 'object' => array('foo' => 'innerFoo', 'bar' => 'innerBar'),
694 $serializer->normalize($objectDummy, null, $context)
698 public function testAttributesContextDenormalize()
700 $normalizer = new ObjectNormalizer(null, null, null, new ReflectionExtractor());
701 $serializer = new Serializer(array($normalizer));
703 $objectInner = new ObjectInner();
704 $objectInner->foo = 'innerFoo';
706 $objectOuter = new ObjectOuter();
707 $objectOuter->bar = 'bar';
708 $objectOuter->setInner($objectInner);
710 $context = array('attributes' => array('bar', 'inner' => array('foo')));
711 $this->assertEquals($objectOuter, $serializer->denormalize(
715 'date' => '2017-02-03',
716 'inner' => array('foo' => 'innerFoo', 'bar' => 'innerBar'),
717 ), ObjectOuter::class, null, $context));
720 public function testAttributesContextDenormalizeConstructor()
722 $normalizer = new ObjectNormalizer(null, null, null, new ReflectionExtractor());
723 $serializer = new Serializer(array($normalizer));
725 $objectInner = new ObjectInner();
726 $objectInner->bar = 'bar';
728 $obj = new DummyWithConstructorObjectAndDefaultValue('a', $objectInner);
730 $context = array('attributes' => array('inner' => array('bar')));
731 $this->assertEquals($obj, $serializer->denormalize(array(
733 'inner' => array('foo' => 'foo', 'bar' => 'bar'),
734 ), DummyWithConstructorObjectAndDefaultValue::class, null, $context));
737 public function testNormalizeSameObjectWithDifferentAttributes()
739 $classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
740 $this->normalizer = new ObjectNormalizer($classMetadataFactory);
741 $serializer = new Serializer(array($this->normalizer));
742 $this->normalizer->setSerializer($serializer);
744 $dummy = new ObjectOuter();
745 $dummy->foo = new ObjectInner();
746 $dummy->foo->foo = 'foo.foo';
747 $dummy->foo->bar = 'foo.bar';
749 $dummy->bar = new ObjectInner();
750 $dummy->bar->foo = 'bar.foo';
751 $dummy->bar->bar = 'bar.bar';
753 $this->assertEquals(array(
760 ), $this->normalizer->normalize($dummy, 'json', array(
761 'attributes' => array(
762 'foo' => array('bar'),
763 'bar' => array('foo'),
774 protected $camelCase;
777 public function getFoo()
782 public function setFoo($foo)
787 public function isBaz()
792 public function setBaz($baz)
797 public function getFooBar()
799 return $this->foo.$this->bar;
802 public function getCamelCase()
804 return $this->camelCase;
807 public function setCamelCase($camelCase)
809 $this->camelCase = $camelCase;
812 public function otherMethod()
814 throw new \RuntimeException('Dummy::otherMethod() should not be called');
817 public function setObject($object)
819 $this->object = $object;
822 public function getObject()
824 return $this->object;
828 class ObjectConstructorDummy
834 public function __construct($foo, $bar, $baz)
841 public function getFoo()
846 public function isBaz()
851 public function otherMethod()
853 throw new \RuntimeException('Dummy::otherMethod() should not be called');
857 abstract class ObjectSerializerNormalizer implements SerializerInterface, NormalizerInterface
861 class ObjectConstructorOptionalArgsDummy
867 public function __construct($foo, $bar = array(), $baz = array())
874 public function getFoo()
879 public function getBaz()
884 public function otherMethod()
886 throw new \RuntimeException('Dummy::otherMethod() should not be called');
890 class ObjectConstructorArgsWithDefaultValueDummy
895 public function __construct($foo = array(), $bar)
901 public function getFoo()
906 public function getBar()
911 public function otherMethod()
913 throw new \RuntimeException('Dummy::otherMethod() should not be called');
917 class ObjectWithStaticPropertiesAndMethods
920 public static $bar = 'A';
922 public static function getBaz()
928 class ObjectTypeHinted
930 public function setFoo(array $f)
947 public function getInner()
952 public function setInner(ObjectInner $inner)
954 $this->inner = $inner;
957 public function setDate(\DateTimeInterface $date)
962 public function getDate()
967 public function setInners(array $inners)
969 $this->inners = $inners;
972 public function getInners()
974 return $this->inners;
984 class FormatAndContextAwareNormalizer extends ObjectNormalizer
986 protected function isAllowedAttribute($classOrObject, $attribute, $format = null, array $context = array())
988 if (in_array($attribute, array('foo', 'bar')) && 'foo_and_bar_included' === $format) {
992 if (in_array($attribute, array('foo', 'bar')) && isset($context['include_foo_and_bar']) && true === $context['include_foo_and_bar']) {
1000 class DummyWithConstructorObject
1005 public function __construct($id, ObjectInner $inner)
1008 $this->inner = $inner;
1011 public function getId()
1016 public function getInner()
1018 return $this->inner;
1022 class DummyWithConstructorInexistingObject
1024 public function __construct($id, Unknown $unknown)
1037 class DummyWithConstructorObjectAndDefaultValue
1042 public function __construct($foo = 'a', ObjectInner $inner)
1045 $this->inner = $inner;
1048 public function getFoo()
1053 public function getInner()
1055 return $this->inner;
1059 class ObjectWithUpperCaseAttributeNames
1061 private $Foo = 'Foo';
1062 public $Bar = 'BarBar';
1064 public function getFoo()