From 5e0161795920b9880e8ceb8b9804f46da65c185d Mon Sep 17 00:00:00 2001 From: Asmir Mustafic Date: Fri, 9 Nov 2018 15:33:17 +0100 Subject: [PATCH] setSerializeNull option is available only on the serialization context --- ContextFactory/ConfiguredContextFactory.php | 3 ++- Tests/ContextFactory/ConfiguredContextFactoryTest.php | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) 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'));