diff --git a/ContextFactory/ConfiguredContextFactory.php b/ContextFactory/ConfiguredContextFactory.php index 2d0e1c3e..cf1d3b88 100644 --- a/ContextFactory/ConfiguredContextFactory.php +++ b/ContextFactory/ConfiguredContextFactory.php @@ -116,7 +116,8 @@ private function configureContext(Context $context) if (!empty($this->groups)) { $context->setGroups($this->groups); } - if ($this->serializeNulls !== null) { + + if (($context instanceof SerializationContext) && $this->serializeNulls !== null) { $context->setSerializeNull($this->serializeNulls); } diff --git a/Tests/ContextFactory/ConfiguredContextFactoryTest.php b/Tests/ContextFactory/ConfiguredContextFactoryTest.php index cf9e7781..4faf0a55 100644 --- a/Tests/ContextFactory/ConfiguredContextFactoryTest.php +++ b/Tests/ContextFactory/ConfiguredContextFactoryTest.php @@ -3,6 +3,7 @@ namespace JMS\SerializerBundle\Tests\ContextFactory; use JMS\Serializer\Context; +use JMS\Serializer\SerializationContext; use JMS\SerializerBundle\ContextFactory\ConfiguredContextFactory; use PHPUnit\Framework\TestCase; @@ -47,7 +48,9 @@ public function testCreateSerializationContext( $context = $object->$factoryMethod(); /** @var Context $context */ $this->assertInstanceOf($expectedContextClass, $context); - $this->assertSame($serializeNulls, $context->shouldSerializeNull()); + if ($context instanceof SerializationContext) { + $this->assertSame($serializeNulls, $context->shouldSerializeNull()); + } $this->assertSame($version, $context->getAttribute('version')); $this->assertSame($groups, $context->getAttribute('groups'));