Skip to content

[Serializer] NameConverter and 'allow_extra_attributes' => false unexpected behaviours #62725

@alex-dev

Description

@alex-dev

Symfony version(s) affected

6.4 and up

Description

When using a serializer with both a NameConverter and 'allow_extra_attributes' => false, the serializer will ignore wrongly cased properties rather than fail as expected.

How to reproduce

class ValueObject {
	public function __construct(public readonly int $someCamelCaseProperty = 0) {
	}
}

$normalizer = new ObjectNormalizer(
	new ClassMetadataFactory(new AttributeLoader()),
	new CamelCaseToSnakeCaseNameConverter(),
);
$result = $normalizer->denormalize(
	['some_camel_case_property' => 1],
	ValueObject::class,
	context: [ObjectNormalizer::ALLOW_EXTRA_ATTRIBUTES => false],
);
assert($result->someCamelCaseProperty === 1);

$result = $normalizer->denormalize(
	['someCamelCaseProperty' => 1],
	ValueObject::class,
	context: [ObjectNormalizer::ALLOW_EXTRA_ATTRIBUTES => false],
);
assert($result->someCamelCaseProperty === 1);

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