protected function restoreObject($entity, array $restore, \ReflectionClass $ref)
    {
        foreach ($restore as $field => $type) {
            if (is_array($entity)) {
                if (!isset($entity[$field])) {
                    continue;
                }

                $entity[$field] = $this->convertToPHPValue($entity[$field], $type);
                continue;
            }

            if (!$ref->hasProperty($field)) {
                if (!isset($entity->$field)) {
                    continue;
                }

                $entity->$field = $this->convertToPHPValue($entity->$field, $type);
                continue;
            }

            $prop = $ref->getProperty($field);
            $prop->setAccessible(true);

            $value = $prop->getValue($entity);
            $value = $this->convertToPHPValue($value, $type);
            $prop->setValue($entity, $value);
        }

        return $entity;
    }