Serializer/Serializer.php
private function doDeserialize($data, $entity)
    {
        $metadata = $this->hydraApi->getMetadataFor(get_class($entity));

        if (null === $metadata) {
            // TODO Improve this error message
            throw new \Exception(sprintf('"%s" cannot be serialized as it is not documented.', get_class($data)));
        }

        $vocabPrefix = $this->router->generate('hydra_vocab', array(), true) . '#';
        $typeIri = ($metadata->isExternalReference())
            ? $metadata->getIri()
            : $vocabPrefix . $metadata->getIri();

        $graph = JsonLD::getDocument($data)->getGraph();
        $node = $graph->getNodesByType($typeIri);

        if (1 !== count($node)) {
            throw new RuntimeException(
                'The passed data contains '. count($node) . ' nodes of the type ' .
                $typeIri . '; expected 1.'
            );
        }

        $node = reset($node);

        foreach ($metadata->getProperties() as $property) {
            if ($property->isReadOnly()) {
                continue;
            }

            // TODO Parse route!
            if (null !== ($route = $property->getRoute())) {
                continue;   // FIXXE Handle properties whose value are URLs
            }

            // TODO Recurse!?
            $propertyIri = ($property->isExternalReference())
                ? $property->getIri()
                : $vocabPrefix . $property->getIri();

            $value = $node->getProperty($propertyIri);
            if ($value instanceof \ML\JsonLD\Value) {
                $value = $value->getValue();
            }

            if (!is_null($value) && $this->hydraApi->hasNormalizer($property->getType())) {
                $normalizer = $this->hydraApi->getNormalizer($property->getType());
                $value = $normalizer->denormalize($value, $property->getType());
            }

            $property->setValue($entity, $value);  // TODO Fix IRI construction

            // if (is_array($value) || ($value instanceof \ArrayAccess) || ($value instanceof \Travesable)) {
            //     $result[$property] = array();
            //     foreach ($value as $val) {
            //         $result[$property][] = $this->doSerialize($val);
            //     }
            // } else {
            //     $result[$property] = $value;
            // }
        }

        return $entity;
    }
private function doDeserialize($data, $entity)
    {
        $metadata = $this->hydraApi->getMetadataFor(get_class($entity));

        if (null === $metadata) {
            // TODO Improve this error message
            throw new \Exception(sprintf('"%s" cannot be serialized as it is not documented.', get_class($data)));
        }

        $vocabPrefix = $this->router->generate('hydra_vocab', array(), true) . '#';
        $typeIri = ($metadata->isExternalReference())
            ? $metadata->getIri()
            : $vocabPrefix . $metadata->getIri();

        $graph = JsonLD::getDocument($data)->getGraph();
        $node = $graph->getNodesByType($typeIri);

        if (1 !== count($node)) {
            throw new RuntimeException(
                'The passed data contains '. count($node) . ' nodes of the type ' .
                $typeIri . '; expected 1.'
            );
        }

        $node = reset($node);

        foreach ($metadata->getProperties() as $property) {
            if ($property->isReadOnly()) {
                continue;
            }

            // TODO Parse route!
            if (null !== ($route = $property->getRoute())) {
                continue;   // FIXXE Handle properties whose value are URLs
            }

            // TODO Recurse!?
            $propertyIri = ($property->isExternalReference())
                ? $property->getIri()
                : $vocabPrefix . $property->getIri();

            $value = $node->getProperty($propertyIri);
            if ($value instanceof \ML\JsonLD\Value) {
                $value = $value->getValue();
            }

            if (!is_null($value) && $this->hydraApi->hasNormalizer($property->getType())) {
                $normalizer = $this->hydraApi->getNormalizer($property->getType());
                $value = $normalizer->denormalize($value, $property->getType());
            }

            $property->setValue($entity, $value);  // TODO Fix IRI construction

            // if (is_array($value) || ($value instanceof \ArrayAccess) || ($value instanceof \Travesable)) {
            //     $result[$property] = array();
            //     foreach ($value as $val) {
            //         $result[$property][] = $this->doSerialize($val);
            //     }
            // } else {
            //     $result[$property] = $value;
            // }
        }

        return $entity;
    }
Deserializes JSON-LD data

@param mixed  $data   The data to deserialize.
@param object $entity The entity into which the data should be
deserialized.

@return object The entity.