protected function setPropertyType(DoctrineClassMetadata $doctrineMetadata, PropertyMetadata $propertyMetadata)
 {
     /** @var \Doctrine\ODM\PHPCR\Mapping\ClassMetadata $doctrineMetadata */
     $propertyName = $propertyMetadata->name;
     if ($doctrineMetadata->hasField($propertyName) && ($fieldType = $this->normalizeFieldType($doctrineMetadata->getTypeOfField($propertyName)))) {
         $field = $doctrineMetadata->getFieldMapping($propertyName);
         if (!empty($field['multivalue'])) {
             $fieldType = 'array';
         }
         $propertyMetadata->setType($fieldType);
     } elseif ($doctrineMetadata->hasAssociation($propertyName)) {
         try {
             $targetEntity = $doctrineMetadata->getAssociationTargetClass($propertyName);
         } catch (\Exception $e) {
             return;
         }
         if (null === $this->tryLoadingDoctrineMetadata($targetEntity)) {
             return;
         }
         if (!$doctrineMetadata->isSingleValuedAssociation($propertyName)) {
             $targetEntity = "ArrayCollection<{$targetEntity}>";
         }
         $propertyMetadata->setType($targetEntity);
     }
 }
 /**
  * @dataProvider providerPublicMethodException
  * @expectedException \Kcs\Serializer\Exception\RuntimeException
  */
 public function testAccessorTypePublicMethodException($getter, $setter)
 {
     $object = new PropertyMetadataPublicMethod();
     $metadata = new PropertyMetadata(get_class($object), 'e');
     $metadata->setAccessor(PropertyMetadata::ACCESS_TYPE_PUBLIC_METHOD, $getter, $setter);
     if (null === $getter) {
         $metadata->getValue($object, new SerializationContext());
     }
     if (null === $setter) {
         $metadata->setValue($object, null);
     }
 }
 protected function setPropertyType(DoctrineClassMetadata $doctrineMetadata, PropertyMetadata $propertyMetadata)
 {
     /** @var \Doctrine\ORM\Mapping\ClassMetadata $doctrineMetadata */
     $propertyName = $propertyMetadata->name;
     if ($doctrineMetadata->hasField($propertyName) && ($fieldType = $this->normalizeFieldType($doctrineMetadata->getTypeOfField($propertyName)))) {
         $propertyMetadata->setType($fieldType);
     } elseif ($doctrineMetadata->hasAssociation($propertyName)) {
         $targetEntity = $doctrineMetadata->getAssociationTargetClass($propertyName);
         if (null === ($targetMetadata = $this->tryLoadingDoctrineMetadata($targetEntity))) {
             return;
         }
         // For inheritance schemes, we cannot add any type as we would only add the super-type of the hierarchy.
         // On serialization, this would lead to only the supertype being serialized, and properties of subtypes
         // being ignored.
         if ($targetMetadata instanceof DoctrineClassMetadata && !$targetMetadata->isInheritanceTypeNone()) {
             return;
         }
         if (!$doctrineMetadata->isSingleValuedAssociation($propertyName)) {
             $targetEntity = "ArrayCollection<{$targetEntity}>";
         }
         $propertyMetadata->setType($targetEntity);
     }
 }
 protected function visitProperty(PropertyMetadata $metadata, $data, Context $context)
 {
     $v = $metadata->getValue($data);
     $v = $this->navigator->accept($v, $metadata->type, $context);
     if (null === $v && !$context->shouldSerializeNull()) {
         return;
     }
     $k = $this->namingStrategy->translateName($metadata);
     if ($metadata->inline) {
         if (is_array($v)) {
             $this->data = array_merge($this->data, $v);
         }
     } else {
         $this->data[$k] = $v;
     }
 }
 protected static function doProcess($annotation, PropertyMetadata $metadata)
 {
     $metadata->setType($annotation->name);
 }
 protected function visitProperty(PropertyMetadata $metadata, $data, Context $context)
 {
     $v = $metadata->getValue($data);
     if ($metadata->xmlAttribute) {
         $attributeName = $this->namingStrategy->translateName($metadata);
         $this->currentNodes = $this->document->createElement('tmp');
         $context->accept($v, $metadata->type);
         $node = $this->createAttributeNode($metadata, $attributeName);
         $node->appendChild($this->createTextNode((string) $this->currentNodes->nodeValue));
         return $this->currentNodes = $node;
     }
     if ($metadata->xmlValue) {
         $this->currentNodes = $this->document->createElement('tmp');
         $context->accept($v, $metadata->type);
         $node = $this->currentNodes->childNodes->item(0);
         $this->currentNodes->removeChild($node);
         return $this->currentNodes = $node;
     }
     if ($metadata->xmlAttributeMap) {
         $attributes = [];
         foreach ($v as $key => $value) {
             $node = $this->createAttributeNode($metadata, $key);
             $node->appendChild($this->createTextNode((string) $value));
             $attributes[] = $node;
         }
         return $this->currentNodes = $attributes;
     }
     if (null === $v && !$context->shouldSerializeNull()) {
         return $this->currentNodes = null;
     }
     $elementName = $this->namingStrategy->translateName($metadata);
     $this->currentNodes = $this->createElement($metadata->xmlNamespace, $elementName);
     $context->accept($v, $metadata->type);
     if (is_object($v) && null !== $v && !$metadata instanceof AdditionalPropertyMetadata && $context->isVisiting($v)) {
         return $this->currentNodes = null;
     }
     if ($metadata->xmlCollectionInline || $metadata->inline) {
         $children = iterator_to_array($this->currentNodes->childNodes);
         foreach ($children as $childNode) {
             $this->currentNodes->removeChild($childNode);
         }
         $this->currentNodes = $children;
     }
     return $this->currentNodes;
 }