Define a context when serializing an object for a request.
public function testSimple() { $annotation = new SerializationContext(['groups' => ['test'], 'serializeNull' => true, 'version' => 1, 'foo' => 'bar']); $this->assertEquals(['test'], $annotation->getGroups()); $this->assertEquals(true, $annotation->getSerializeNull()); $this->assertEquals(1, $annotation->getVersion()); $this->assertEquals(['foo' => 'bar'], $annotation->getAttributes()); }
public function testDeprecatedSerializerContext() { $this->disableDeprecationWarning(); $annotation = new SerializationContext([]); $this->assertSame(SerializationContext::NAME, $annotation->getName()); $this->assertFalse($annotation->allowMultiple()); $this->enableDeprecationWarning(); }
public function testSimple() { $this->disableDeprecationWarning(); $annotation = new SerializationContext(['groups' => ['test'], 'serializeNull' => true, 'version' => 1, 'enableMaxDepthChecks' => true, 'foo' => 'bar']); $this->assertEquals(['test'], $annotation->getContext()['groups']); $this->assertEquals(true, $annotation->getContext()['serializeNull']); $this->assertEquals(1, $annotation->getContext()['version']); $this->assertEquals(true, $annotation->getContext()['enableMaxDepthChecks']); $this->assertEquals('bar', $annotation->getContext()['foo']); $this->enableDeprecationWarning(); }
/** * Will set annotation data to $method * * @param Method $method * @param SerializationContext $annotation * * @return null */ public function handle(Method $method, $annotation) { $method->setSerializationContext(['groups' => $annotation->getGroups(), 'serializeNull' => $annotation->getSerializeNull(), 'version' => $annotation->getVersion(), 'attributes' => $annotation->getAttributes()]); }