Skip to content

Commit

Permalink
Merge pull request #694 from schmittjoh/context-factory-v2
Browse files Browse the repository at this point in the history
setSerializeNull option is available only on the serialization context
  • Loading branch information
goetas authored Nov 9, 2018
2 parents 017a85e + 5e01617 commit 1ea6bf7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
3 changes: 2 additions & 1 deletion ContextFactory/ConfiguredContextFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
5 changes: 4 additions & 1 deletion Tests/ContextFactory/ConfiguredContextFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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'));
Expand Down

0 comments on commit 1ea6bf7

Please sign in to comment.