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;
    }