/**
  * Convert raw property values to the correct type according to a node type configuration
  *
  * @param NodeType $nodeType
  * @param string $propertyName
  * @param string $rawValue
  * @param Context $context
  * @return mixed
  */
 public function convert(NodeType $nodeType, $propertyName, $rawValue, Context $context)
 {
     $propertyType = $nodeType->getPropertyType($propertyName);
     switch ($propertyType) {
         case 'string':
             return $rawValue;
         case 'reference':
             return $this->convertReference($rawValue, $context);
         case 'references':
             return $this->convertReferences($rawValue, $context);
         case 'DateTime':
             return $this->convertDateTime($rawValue);
         case 'integer':
             return $this->convertInteger($rawValue);
         case 'boolean':
             return $this->convertBoolean($rawValue);
         case 'array':
             return $this->convertArray($rawValue);
         default:
             $innerType = $propertyType;
             if ($propertyType !== null) {
                 try {
                     $parsedType = \TYPO3\Flow\Utility\TypeHandling::parseType($propertyType);
                     $innerType = $parsedType['elementType'] ?: $parsedType['type'];
                 } catch (\TYPO3\Flow\Utility\Exception\InvalidTypeException $exception) {
                 }
             }
             if ((is_string($rawValue) || is_array($rawValue)) && $this->objectManager->isRegistered($innerType) && $rawValue !== '') {
                 $propertyMappingConfiguration = new MvcPropertyMappingConfiguration();
                 $propertyMappingConfiguration->allowOverrideTargetType();
                 $propertyMappingConfiguration->allowAllProperties();
                 $propertyMappingConfiguration->skipUnknownProperties();
                 $propertyMappingConfiguration->setTypeConverterOption('TYPO3\\Flow\\Property\\TypeConverter\\PersistentObjectConverter', \TYPO3\Flow\Property\TypeConverter\PersistentObjectConverter::CONFIGURATION_MODIFICATION_ALLOWED, true);
                 $propertyMappingConfiguration->setTypeConverterOption('TYPO3\\Flow\\Property\\TypeConverter\\PersistentObjectConverter', \TYPO3\Flow\Property\TypeConverter\PersistentObjectConverter::CONFIGURATION_CREATION_ALLOWED, true);
                 return $this->propertyMapper->convert($rawValue, $propertyType, $propertyMappingConfiguration);
             } else {
                 return $rawValue;
             }
     }
 }
 /**
  * Convert array to change interface
  *
  * @param array $changeData
  * @return ChangeInterface
  */
 protected function convertChangeData($changeData)
 {
     $type = $changeData['type'];
     if (!isset($this->typeMap[$type])) {
         return new \TYPO3\Flow\Error\Error(sprintf('Could not convert change type %s, it is unknown to the system', $type));
     }
     $changeClass = $this->typeMap[$type];
     $changeClassInstance = $this->objectManager->get($changeClass);
     $changeClassInstance->injectPersistenceManager($this->persistenceManager);
     $subjectContextPath = $changeData['subject'];
     $subject = $this->nodeService->getNodeFromContextPath($subjectContextPath);
     if ($subject instanceof \TYPO3\Flow\Error\Error) {
         return $subject;
     }
     $changeClassInstance->setSubject($subject);
     if (isset($changeData['reference']) && method_exists($changeClassInstance, 'setReference')) {
         $referenceContextPath = $changeData['reference'];
         $reference = $this->nodeService->getNodeFromContextPath($referenceContextPath);
         if ($reference instanceof \TYPO3\Flow\Error\Error) {
             return $reference;
         }
         $changeClassInstance->setReference($reference);
     }
     if (isset($changeData['payload'])) {
         foreach ($changeData['payload'] as $propertyName => $value) {
             if (!in_array($propertyName, $this->disallowedPayloadProperties)) {
                 $methodParameters = $this->reflectionService->getMethodParameters($changeClass, ObjectAccess::buildSetterMethodName($propertyName));
                 $methodParameter = current($methodParameters);
                 $targetType = $methodParameter['type'];
                 $value = $this->propertyMapper->convert($value, $targetType);
                 ObjectAccess::setProperty($changeClassInstance, $propertyName, $value);
             }
         }
     }
     return $changeClassInstance;
 }