/**
  * Generate a new image variant from given data.
  *
  * @param ImageVariant $asset
  * @return string
  */
 public function createImageVariantAction(ImageVariant $asset)
 {
     $this->assetRepository->add($asset);
     $propertyMappingConfiguration = new PropertyMappingConfiguration();
     // This will not be sent as "application/json" as we need the JSON string and not the single variables.
     return json_encode($this->entityToIdentityConverter->convertFrom($asset, 'array', [], $propertyMappingConfiguration));
 }
 private function buildNodeProperty(NodeInterface $node, $propertyName, $dataType)
 {
     if (substr($propertyName, 0, 1) === '_') {
         $propertyValue = ObjectAccess::getProperty($node, substr($propertyName, 1));
     } else {
         $propertyValue = $node->getProperty($propertyName);
     }
     // Enforce an integer value for integer properties as otherwise javascript will give NaN and VIE converts it to an array containing 16 times 'NaN'
     if ($dataType === 'integer') {
         $propertyValue = (int) $propertyValue;
     }
     // Serialize boolean values to String
     if ($dataType === 'boolean') {
         return $propertyValue ? 'true' : 'false';
     }
     // Serialize array values to String
     if ($dataType === 'array') {
         return $propertyValue;
     }
     // Serialize date values to String
     if ($dataType === 'DateTime') {
         if (!$propertyValue instanceof \DateTimeInterface) {
             return '';
         }
         $value = clone $propertyValue;
         return $value->setTimezone(new \DateTimeZone('UTC'))->format(\DateTime::W3C);
     }
     // Serialize node references to node identifiers
     if ($dataType === 'references') {
         $nodeIdentifiers = array();
         if (is_array($propertyValue)) {
             /** @var $subNode NodeInterface */
             foreach ($propertyValue as $subNode) {
                 $nodeIdentifiers[] = $subNode->getIdentifier();
             }
         }
         return $nodeIdentifiers;
     }
     // Serialize node reference to node identifier
     if ($dataType === 'reference') {
         if ($propertyValue instanceof NodeInterface) {
             return $propertyValue->getIdentifier();
         } else {
             return '';
         }
     }
     if ($propertyValue instanceof \TYPO3\Media\Domain\Model\ImageInterface) {
         $propertyMappingConfiguration = new \TYPO3\Flow\Property\PropertyMappingConfiguration();
         return $this->entityToIdentityConverter->convertFrom($propertyValue, 'array', array(), $propertyMappingConfiguration);
     }
     // Serialize an Asset to JSON (the NodeConverter expects JSON for object type properties)
     if ($dataType === ltrim('TYPO3\\Media\\Domain\\Model\\Asset', '\\') && $propertyValue !== null) {
         if ($propertyValue instanceof \TYPO3\Media\Domain\Model\Asset) {
             return $this->persistenceManager->getIdentifierByObject($propertyValue);
         }
     }
     // Serialize an array of Assets to JSON
     if (is_array($propertyValue)) {
         $parsedType = \TYPO3\Flow\Utility\TypeHandling::parseType($dataType);
         if ($parsedType['elementType'] === ltrim('TYPO3\\Media\\Domain\\Model\\Asset', '\\')) {
             $convertedValues = array();
             foreach ($propertyValue as $singlePropertyValue) {
                 if ($singlePropertyValue instanceof \TYPO3\Media\Domain\Model\Asset) {
                     $convertedValues[] = $this->persistenceManager->getIdentifierByObject($singlePropertyValue);
                 }
             }
             return $convertedValues;
         }
     }
     return $propertyValue === null ? '' : $propertyValue;
 }