/** * Whether the property should be skipped. * * @param PropertyMetadata $property * * @return boolean */ public function shouldSkipProperty(PropertyMetadata $property, Context $context) { switch ($context->getDirection()) { case GraphNavigator::DIRECTION_SERIALIZATION: if (isset($property->exposeToSerialize) && $property->exposeToSerialize !== true) { return true; } break; case GraphNavigator::DIRECTION_DESERIALIZATION: if (isset($property->exposeToDeserialize) && $property->exposeToDeserialize !== true) { return true; } break; } return false; }
/** * Asserts during serialization, that provided data is either an object, or has custom handler registered. * * @param mixed $data * @param array $type * @param \JMS\Serializer\Context $context * @throws \LogicException Thrown, when a primitive type has no custom handler registered. */ public function assertObjectOrCustomHandlerForSerialization($data, $type, Context $context) { //Ok during deserialization if ($context->getDirection() === static::DIRECTION_DESERIALIZATION) { return; } //Ok, if data is an object if (is_object($data) || $data === null) { return; } //Ok, if custom handler exists if (null !== $this->handlerRegistry->getHandler($context->getDirection(), $type['name'], $context->getFormat())) { return; } //Not ok - throw an exception throw new LogicException('Expected object but got ' . gettype($data) . '. Do you have the wrong @Type mapping or could this be a Doctrine many-to-many relation?'); }