diff --git a/src/Symfony/Component/Serializer/Normalizer/GetSetMethodNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/GetSetMethodNormalizer.php index 2a15d46d63..3d2c0665be 100644 --- a/src/Symfony/Component/Serializer/Normalizer/GetSetMethodNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/GetSetMethodNormalizer.php @@ -87,7 +87,8 @@ class GetSetMethodNormalizer extends AbstractObjectNormalizer !$method->isStatic() && ( ((0 === strpos($method->name, 'get') && 3 < $methodLength) || - (0 === strpos($method->name, 'is') && 2 < $methodLength)) && + (0 === strpos($method->name, 'is') && 2 < $methodLength) || + (0 === strpos($method->name, 'has') && 3 < $methodLength)) && 0 === $method->getNumberOfRequiredParameters() ) ; @@ -133,6 +134,11 @@ class GetSetMethodNormalizer extends AbstractObjectNormalizer if (is_callable(array($object, $isser))) { return $object->$isser(); } + + $haser = 'has'.$ucfirsted; + if (is_callable(array($object, $haser))) { + return $object->$haser(); + } } /** diff --git a/src/Symfony/Component/Serializer/Tests/Normalizer/GetSetMethodNormalizerTest.php b/src/Symfony/Component/Serializer/Tests/Normalizer/GetSetMethodNormalizerTest.php index ee0a159f06..6358cd7a90 100644 --- a/src/Symfony/Component/Serializer/Tests/Normalizer/GetSetMethodNormalizerTest.php +++ b/src/Symfony/Component/Serializer/Tests/Normalizer/GetSetMethodNormalizerTest.php @@ -497,6 +497,23 @@ class GetSetMethodNormalizerTest extends TestCase $this->assertEquals('bar', $obj->getFoo()); } + public function testHasGetterDenormalize() + { + $obj = $this->normalizer->denormalize(array('foo' => true), ObjectWithHasGetterDummy::class); + $this->assertTrue($obj->hasFoo()); + } + + public function testHasGetterNormalize() + { + $obj = new ObjectWithHasGetterDummy(); + $obj->setFoo(true); + + $this->assertEquals( + array('foo' => true), + $this->normalizer->normalize($obj, 'any') + ); + } + public function testMaxDepth() { $classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader())); @@ -807,3 +824,18 @@ class ObjectWithJustStaticSetterDummy self::$foo = $foo; } } + +class ObjectWithHasGetterDummy +{ + private $foo; + + public function setFoo($foo) + { + $this->foo = $foo; + } + + public function hasFoo() + { + return $this->foo; + } +}