Skip to content

Special '*' serialization group #6820

Open
@SergeyCherenkov

Description

@SergeyCherenkov

Description

The SymfonySerializer has a special group * that allows you to serialize all fields.

symfony/symfony#33540
symfony/symfony#32622
symfony/symfony@de58759

The SerializerPropertyMetadataFactory treats it as a regular group.

namespace ApiPlatform\Metadata\Property\Factory;

final class SerializerPropertyMetadataFactory implements PropertyMetadataFactoryInterface
{
    // ...
    private function transformReadWrite(ApiProperty $propertyMetadata, string $resourceClass, string $propertyName, ?array $normalizationGroups = null, ?array $denormalizationGroups = null): ApiProperty
    {
        $serializerAttributeMetadata = $this->getSerializerAttributeMetadata($resourceClass, $propertyName);
        $groups = $serializerAttributeMetadata ? $serializerAttributeMetadata->getGroups() : [];
        $ignored = $serializerAttributeMetadata && $serializerAttributeMetadata->isIgnored();

        if (false !== $propertyMetadata->isReadable()) {
            $propertyMetadata = $propertyMetadata->withReadable(!$ignored && (null === $normalizationGroups || array_intersect($normalizationGroups, $groups)));
        }

        if (false !== $propertyMetadata->isWritable()) {
            $propertyMetadata = $propertyMetadata->withWritable(!$ignored && (null === $denormalizationGroups || array_intersect($denormalizationGroups, $groups)));
        }

        return $propertyMetadata;
    }
    // ...
}

Wouldn't it be correct to add handling for this group in API Platform?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions