@param Serializer $serializer
@param string     $className
@param array      $value

@return mixed
431767
public static function unserialize(Serializer $serializer, $className, array $value)
    {
        $data = $serializer->unserialize($value[Serializer::SCALAR_VALUE]);

        /* @var SplFixedArray $instance */
        $ref = new ReflectionClass($className);
        $instance = $ref->newInstanceWithoutConstructor();

        $instance->setSize(count($data));
        foreach ($data as $k => $v) {
            $instance[$k] = $v;
        }

        return $instance;
    }
1338137
public static function serializeValue($value)
    {
        if ($value instanceof JsonSerializable || $value instanceof \JsonSerializable) {
            return $value->jsonSerialize();
        }

        if (is_object($value)) {
            foreach (get_object_vars($value) as $nestedKey => $nestedValue) {
                $value->{$nestedKey} = self::serializeValue($nestedValue);
            }

            return $value;
        }

        if (is_array($value)) {
            foreach ($value as &$nestedValue) {
                $nestedValue = self::serializeValue($nestedValue);
            }

            return $value;
        }

        if ($value instanceof DateTime || $value instanceof \DateTimeInterface) {
            throw new DomainException('Please wrap your DateTime objects with Aplazame\Serializer\Date::fromDateTime');
        }

        if (is_float($value)) {
            throw new DomainException('Please wrap your float values with Aplazame\Serializer\Decimal::fromFloat');
        }

        return $value;
    }
782532
public function getSerializerHandledClass($serializer)
    {
        if (method_exists($serializer, 'getClass')) {
            // 1. the serializer implements the getClass method, so we just call it
            //    this is the recommended way because it's more efficient than using reflection
            return $serializer->getClass();
        } else {
            // 2. else, we try to find the correct serializer by using the type hint of the `serialize` method
            //    this is not always possible, because some serializers can not use type hint (mostly because of an Interface),
            //    so for this case the `getClass` method is required
            $p = new \ReflectionParameter([get_class($serializer), 'serialize'], 0);

            return $p->getClass()->getName();
        }
    }
43224
protected function serializeObject(array $value)
    {
        if (null !== $this->mappings) {
            /** @var \NilPortugues\Api\Mapping\Mapping $mapping */
            foreach ($this->mappings as $class => $mapping) {
                RecursiveDeleteHelper::deleteProperties($this->mappings, $value, $class);
                RecursiveRenamerHelper::renameKeyValue($this->mappings, $value, $class);
            }
        }

        $this->setResponseMeta($value);
        $this->setResponseLinks($value);
        self::formatScalarValues($value);
        RecursiveDeleteHelper::deleteKeys($value, [Serializer::CLASS_IDENTIFIER_KEY]);
        self::flattenObjectsWithSingleKeyScalars($value);
        $this->recursiveSetKeysToUnderScore($value);

        return $value;
    }
214266
public function deserializeCollection(string $serialized, ClassName $className)
    {
        $objectsAsArray = $this->decodeJson($serialized);

        $objects = [];
        foreach ($objectsAsArray as $attribute => $object) {
            $objects[$attribute] = $this->setObjectForClass($className, $object);
        }

        return $objects;
    }
979781
public static function getRelationshipAsPropertyName(
        $value,
        $className,
        ReflectionClass $reflection,
        Driver $serializer
    ) {
        $methods = [];
        foreach ($reflection->getMethods(ReflectionMethod::IS_PUBLIC) as $method) {
            if (ltrim($method->class, '\\') !== ltrim($className, '\\')) {
                continue;
            }

            $name = $method->name;
            $reflectionMethod = $reflection->getMethod($name);

            if (!self::isAllowedEloquentModelFunction($name) || $reflectionMethod->getNumberOfParameters() > 0) {
                continue;
            }

            if (in_array($name, $value->getHidden(), true)) {
                continue;
            }

            try {
                $returned = $reflectionMethod->invoke($value);

                if (!(\is_object($returned) && self::isAnEloquentRelation($returned))) {
                    continue;
                }

                $relationData = $returned->getResults();

                if ($relationData instanceof Traversable) {
                    //Something traversable with Models
                    $items = [];

                    foreach ($relationData as $model) {
                        if ($model instanceof Model) {
                            $items[] = self::getModelData($serializer, $model);
                        }
                    }

                    $methods[$name] = [
                        Serializer::MAP_TYPE => 'array',
                        Serializer::SCALAR_VALUE => $items,
                    ];
                } elseif ($relationData instanceof Model) {
                    //Single element returned.
                    $methods[$name] = self::getModelData($serializer, $relationData);
                }

            } catch (ErrorException $e) {
            }
        }

        return $methods;
    }
1670
protected static function prepareSerializer(SerializerInterface $serializer = null)
    {
        if (null === $serializer) {
            $serializer = SerializerFactory::create();
        }

        return $serializer;
    }
1363766
protected function serialize($value)
    {
        if (!is_array($value)) {
            return $value;
        }
        return Serialize::serialize($value, $this->serializer);
    }
713716
protected static function assertItTypeMemberIsExpectedValue(
        array $data,
        JsonApiSerializer $serializer,
        $className,
        ErrorBag $errorBag
    ) {
        $mapping = $serializer->getTransformer()->getMappingByAlias($data[JsonApiTransformer::TYPE_KEY]);

        if (null === $mapping || $mapping->getClassName() !== $className) {
            $errorBag->offsetSet(null, new InvalidTypeError($data[JsonApiTransformer::TYPE_KEY]));
            throw new DataException();
        }
    }
732187
public static function getAttributes(array $data, JsonApiSerializer $serializer)
    {
        $mapping = $serializer->getTransformer()->getMappingByAlias($data[JsonApiTransformer::TYPE_KEY]);
        $aliases = $mapping->getAliasedProperties();
        $keys = str_replace(
            array_values($aliases),
            array_keys($aliases),
            array_keys($data[JsonApiTransformer::ATTRIBUTES_KEY])
        );

        return array_combine($keys, array_values($data[JsonApiTransformer::ATTRIBUTES_KEY]));
    }
573332
private function buildFactory(string $className) : callable
    {
        $reflectionClass = $this->getReflectionClass($className);

        if ($this->isInstantiableViaReflection($reflectionClass)) {
            return [$reflectionClass, 'newInstanceWithoutConstructor'];
        }

        $serializedString = sprintf(
            '%s:%d:"%s":0:{}',
            self::SERIALIZATION_FORMAT_AVOID_UNSERIALIZER,
            strlen($className),
            $className
        );

        $this->checkIfUnSerializationIsSupported($reflectionClass, $serializedString);

        return static function () use ($serializedString) {
            return unserialize($serializedString);
        };
    }
1190078
protected function serializeObject($value)
    {
        if (self::$objectStorage->contains($value)) {
            return [self::CLASS_IDENTIFIER_KEY => '@'.self::$objectStorage[$value]];
        }

        self::$objectStorage->attach($value, self::$objectMappingIndex++);

        $reflection = new ReflectionClass($value);
        $className = $reflection->getName();

        return $this->serializeInternalClass($value, $className, $reflection);
    }
1302559
protected function isClassOrNullInSerializedObjectAfterField($serializedObject, $fieldName, $className)
    {
        $fieldAndClassPattern = '/'. preg_quote($fieldName, '/') . '";((?P<null>N);|O:\d+:"(?P<class>[\w\\\\]+)":)/';
        $matchFound = preg_match($fieldAndClassPattern, $serializedObject, $matches) === 1;

        return $matchFound &&
            (
                (isset($matches['class']) && $matches['class'] === $className) ||
                (isset($matches['null']) && $matches['null'] === 'N')
            );
    }
859135
public static function unserialize(Serializer $serializer, $className, array $value)
    {
        $ref = new ReflectionClass($className);

        foreach ($value as &$v) {
            if (\is_array($v)) {
                $v = $serializer->unserialize($v);
            }
        }

        return $ref->newInstanceArgs($value);
    }
453577
protected function serializeData($value)
    {
        $this->guardForUnsupportedValues($value);

        if ($this->isInstanceOf($value, 'SplFixedArray')) {
            return SplFixedArraySerializer::serialize($this, $value);
        }

        if (\is_object($value)) {
            return $this->serializeObject($value);
        }

        $type = (\gettype($value) && $value !== null) ? \gettype($value) : 'string';
        $func = $this->serializationMap[$type];

        return $this->$func($value);
    }
779509
protected function createDataObjectFrom($value, $className)
    {
        // If the value is already the correct object, return it unaltered
        if ($value instanceof $className) {
            return $value;
        }

        // Convert object to array so it can be used to set  attributes in the DataObject
        if ($value instanceof Arrayable) {

            $value = $value->toArray();

        }  elseif (is_object($value)) {

            $value = json_decode(json_encode($value), true);
        }

        // Make validation fail if value could not be converted to an array
        if ( ! is_array($value)) {
            return false;
        }


        // Build an instance of the DataObject
        $dataObjectClass = $className;

        try {

            $dataObject = new $dataObjectClass($value);

        } catch (Throwable $e) {

            throw new InvalidArgumentException($dataObjectClass . ' is not instantiable as a DataObject', 0, $e);
        }

        if ( ! ($dataObject instanceof DataObjectInterface)) {

            throw new InvalidArgumentException($dataObjectClass . ' is not a validatable DataObject');
        }

        return $dataObject;
    }
367823
public function get($id, $className, callable $callable)
    {
        try {
            QueryObject::assert($this->serializer, $this->fields, $this->included, new Sorting(), $this->errorBag, $className);
            $data = $callable();

            if (empty($data)) {
                $mapping = $this->serializer->getTransformer()->getMappingByClassName($className);

                return $this->resourceNotFound(new ErrorBag([new NotFoundError($mapping->getClassAlias(), $id)]));
            }

            $response = $this->response($this->serializer->serialize($data, $this->fields, $this->included));
        } catch (Exception $e) {
            $response = $this->getErrorResponse($e);
        }

        return $response;
    }