@param Driver $serializer
@param Model  $model

@return array
356411
protected static function getModelData(Driver $serializer, Model $model)
    {
        $stdClass = (object) $model->attributesToArray();
        $data = $serializer->serialize($stdClass);
        $data[Serializer::CLASS_IDENTIFIER_KEY] = get_class($model);

        return $data;
    }
293693
protected function serializeResource(SerializerAbstract $serializer, $data)
    {
        $includeAttributes = true;
        $resourceKey = $this->resource->getResourceKey();
        if ($this->isRelationships() && $this->isRootScope()) {
            $includeAttributes = false;
        }

        if ($this->resource instanceof Collection) {
            return $serializer->collection($resourceKey, $data, $includeAttributes);
        }

        if ($this->resource instanceof Item) {
            return $serializer->item($resourceKey, $data, $includeAttributes);
        }

        return $serializer->null();
    }
873788
public function resolveSerializer($resource, array $parameters = [], $version = null)
    {
        return $this->resolve('serializer', $resource, $parameters, $version);
    }
383107
public function getAll(Model $model) {
        return $model->find('all', array(
            'order' => array($model->alias . '.' . $model->displayField => 'ASC'),
            'cache' => $model->alias . '::getAll',
            'cacheExpires' => $this->getExpiration($model)
        ));
    }
417819
protected function serializeHasMany(Model $owner, array $models = null, AdapterInterface $adapter)
    {
        if (empty($models)) {
            return $this->serialize(null, $adapter);
        }
        return $this->serializeArray($models, $adapter);
    }
770287
public function filterFields(Model $model, $filter = array()) {
        if (empty($filter) || $filter === '*') {
            return $model->fields;
        }

        $fields = array();

        foreach ($filter as $field) {
            list($table, $field) = pluginSplit($field);

            $fields[$field] = $model->fields[$field];
        }

        return $fields;
    }
757004
private function add(JWESerializer $serializer): self
    {
        $this->serializers[$serializer->name()] = $serializer;

        return $this;
    }
667069
public function isValidSerializer($serializer): bool
    {
        if ($serializer === false) {
            // False is a valid value (forces serialization to be off)
            return true;
        }
        if ($serializer instanceof SerializerInterface) {
            return true;
        }
        if (\is_callable($serializer)) {
            return true;
        }

        return false;
    }
1352162
def _resolve_serializer(self, serializer):
        
        if isinstance(serializer, Serializer):
            return serializer

        if serializer in self._serializers:
            return self._serializers[serializer]

        raise RuntimeError('Unsupported serializer')
74393
protected function getDefaultAttributes($driver)
    {
        if (! ($driver['driver'] instanceof DriverInterface)) {
            throw new InvalidArgumentException(
                get_class($this).' can only serialize instances of '.DriverInterface::class
            );
        }

        $driver = $driver['driver'];

        return [
            'fields' => $driver->availableSettings(),
        ];
    }
456219
public function getList(Model $model) {
        return $model->find('list', array(
            'order' => array($model->alias . '.' . $model->displayField => 'ASC'),
            'cache' => $model->alias . '::getList',
            'cacheExpires' => $this->getExpiration($model)
        ));
    }
1670
protected static function prepareSerializer(SerializerInterface $serializer = null)
    {
        if (null === $serializer) {
            $serializer = SerializerFactory::create();
        }

        return $serializer;
    }
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;
    }
1276741
public function save(Driver $driver, ModelInterface $model)
    {
        $this->managerFactory->setModelClass(get_class($model));
        $manager = $this->managerFactory->getManager($driver);
        $preSaveEvent = new FilterModelEvent();
        $preSaveEvent->setModel($model);
        $preSaveEvent->setManager($manager);
        $this->eventSubscriber->subscribe(Constants::PRE_SAVE, $preSaveEvent);

        try {
            $manager->save($preSaveEvent->getModel());

            $postSaveEvent = new FilterModelEvent();
            $postSaveEvent->setManager($manager);
            $postSaveEvent->setModel($model);
            $this->eventSubscriber->subscribe(Constants::POST_SAVE, $postSaveEvent);
        } catch (\Exception $exception) {
            $this->errorMessage = 'message.save_failed';

            return false;
        }

        return true;
    }
1128383
public static function toArray(ResourceAbstract $resource, $serializer = DataArraySerializer::class)
    {
        $manager = new Manager();
        $manager->setSerializer(new $serializer());
        return $manager->createData($resource)->toArray();
    }
504551
public static function applySerializers(array $serializers, $data) {
		return array_reduce($serializers, function ($serializedData, $serializer) {
			return $serializer->apply($serializedData);
		}, $data);
	}
300153
public synchronized void registerSerializer(Serializer serializer) {
    Class objClass = getSerializerType(serializer);
    if (!serializers.containsKey(objClass)) {
      int index = COUNTER.getAndIncrement();
      serializers.put(objClass, new SerializerWrapper(index, serializer));
      if (serializersArray.length <= index) {
        serializersArray = Arrays.copyOf(serializersArray, index + 1);
      }
      serializersArray[index] = serializer;

      LOGGER.info(String
          .format("Registered new serializer '%s' %n  for '%s' at index %d", serializer.getClass().getName(),
              objClass.getName(), index));
    }
  }