lib/Sds/DoctrineExtensions/Serializer/Serializer.php
public function applySerializeMetadataToArray(array $array, $className) {

        $classMetadata = $this->documentManager->getClassMetadata($className);
        $fieldList = $this->fieldListForSerialize($classMetadata);
        $return = array_merge($array, $this->serializeClassNameAndDiscriminator($classMetadata));

        foreach ($classMetadata->fieldMappings as $field=>$mapping){

            if ( ! in_array($field, $fieldList)){
                if (isset($return[$field])){
                    unset($return[$field]);
                }
                continue;
            }

            if ( isset($mapping['id']) && $mapping['id'] && isset($array['_id'])){
                $return[$field] = $array['_id'];
                unset($return['_id']);
            }

            if ( ! isset($return[$field])){
                continue;
            }

            $return[$field] = $this->applySerializeMetadataToField($return[$field], $field, $className);
        }

        return $return;
    }
public function applySerializeMetadataToArray(array $array, $className) {

        $classMetadata = $this->documentManager->getClassMetadata($className);
        $fieldList = $this->fieldListForSerialize($classMetadata);
        $return = array_merge($array, $this->serializeClassNameAndDiscriminator($classMetadata));

        foreach ($classMetadata->fieldMappings as $field=>$mapping){

            if ( ! in_array($field, $fieldList)){
                if (isset($return[$field])){
                    unset($return[$field]);
                }
                continue;
            }

            if ( isset($mapping['id']) && $mapping['id'] && isset($array['_id'])){
                $return[$field] = $array['_id'];
                unset($return['_id']);
            }

            if ( ! isset($return[$field])){
                continue;
            }

            $return[$field] = $this->applySerializeMetadataToField($return[$field], $field, $className);
        }

        return $return;
    }
Will take an associative array representing a document, and apply the
serialization metadata rules to that array.

@param array $array
@param string $className
@param \Doctrine\ODM\MongoDB\DocumentManager $documentManager
@return array