diff --git a/src/JMS/Serializer/Metadata/Driver/AnnotationDriver.php b/src/JMS/Serializer/Metadata/Driver/AnnotationDriver.php index 30fe6142d..013acc162 100644 --- a/src/JMS/Serializer/Metadata/Driver/AnnotationDriver.php +++ b/src/JMS/Serializer/Metadata/Driver/AnnotationDriver.php @@ -211,10 +211,10 @@ public function loadMetadataForClass(\ReflectionClass $class) } } - $propertyMetadata->setAccessor($accessType, $accessor[0], $accessor[1]); if ((ExclusionPolicy::NONE === $exclusionPolicy && ! $isExclude) || (ExclusionPolicy::ALL === $exclusionPolicy && $isExpose)) { + $propertyMetadata->setAccessor($accessType, $accessor[0], $accessor[1]); $classMetadata->addPropertyMetadata($propertyMetadata); } } diff --git a/tests/JMS/Serializer/Tests/Fixtures/GetSetObject.php b/tests/JMS/Serializer/Tests/Fixtures/GetSetObject.php index c6a9722b0..a3e936f41 100644 --- a/tests/JMS/Serializer/Tests/Fixtures/GetSetObject.php +++ b/tests/JMS/Serializer/Tests/Fixtures/GetSetObject.php @@ -19,6 +19,7 @@ namespace JMS\Serializer\Tests\Fixtures; use JMS\Serializer\Annotation\AccessType; +use JMS\Serializer\Annotation\Exclude; use JMS\Serializer\Annotation\Type; use JMS\Serializer\Annotation\ReadOnly; @@ -36,6 +37,12 @@ class GetSetObject */ private $readOnlyProperty = 42; + /** + * This property should be exlcluded + * @Exclude() + */ + private $excludedProperty; + public function getId() { throw new \RuntimeException('This should not be called.');