core icon indicating copy to clipboard operation
core copied to clipboard

ObjectMapper allow to disable through a flag

Open soyuka opened this issue 3 months ago • 0 comments

API Platform version(s) affected: 4.2

It's quite annoying not to be able to disable automatic mapping we should move this logic:


        $request = $context['request'] ?? null;
        $entityClass = null;
        if (($options = $operation->getStateOptions()) && $options instanceof Options && $options->getEntityClass()) {
            $entityClass = $options->getEntityClass();
        }

        if (($options = $operation->getStateOptions()) && $options instanceof OdmOptions && $options->getDocumentClass()) {
            $entityClass = $options->getDocumentClass();
        }

        // Look for Mapping metadata
        if ($this->objectMapperMetadata) {
            if (!$this->canBeMapped($operation->getClass()) && (!$entityClass || !$this->canBeMapped($entityClass))) {
                return $data;
            }
        } elseif (!(new \ReflectionClass($operation->getClass()))->getAttributes(Map::class) && !(new \ReflectionClass($entityClass))->getAttributes(Map::class)) {
            return $data;
        }

To an operation flag inside a metadata factory and check this flag.

soyuka avatar Nov 17 '25 10:11 soyuka