Skip to content

Navigation Menu

Sign in
Appearance settings
Sign up
Appearance settings

[Serializer] Let DISABLE_TYPE_ENFORCEMENT keep strings that cannot be converted - #65640

#65640
Merged
nicolas-grekas merged 1 commit into
symfony:8.1symfony/symfony:8.1from
nicolas-grekas:serializer-type-enforcement-opt-outnicolas-grekas/symfony:serializer-type-enforcement-opt-outCopy head branch name to clipboard
Aug 25, 2026
Merged

[Serializer] Let DISABLE_TYPE_ENFORCEMENT keep strings that cannot be converted#65640
nicolas-grekas merged 1 commit into
symfony:8.1symfony/symfony:8.1from
nicolas-grekas:serializer-type-enforcement-opt-outnicolas-grekas/symfony:serializer-type-enforcement-opt-outCopy head branch name to clipboard

Conversation

@nicolas-grekas

Copy link
Copy Markdown
Member
Q A
Branch? 8.1
Bug fix? yes
New feature? no
Deprecations? no
Issues Fix #65623
License MIT

For formats where every value is a string (XML, CSV, and the query string or form data mapped by #[MapQueryString] and #[MapRequestPayload]), AbstractObjectNormalizer converts the string to the declared bool, int or float. When the conversion is impossible, it throws a NotNormalizableValueException before it reads DISABLE_TYPE_ENFORCEMENT, so the option has no effect on those formats. Since #65291 the same applies to the elements of a scalar collection, which is the case of #65623: the values of a list<int> property used to reach the validator, they now stop at the serializer, and the validator never runs.

This PR makes DISABLE_TYPE_ENFORCEMENT cover those conversions: a string that cannot be converted is kept as is, the same as for formats without conversion. The default behavior does not change. Without the option, the same exception is thrown, with the same message and path.

For the DTO of #65623, the property keeps its list<positive-int> type and the validator is in charge of the values:

#[MapQueryString(serializationContext: [AbstractObjectNormalizer::DISABLE_TYPE_ENFORCEMENT => true])] QueryString $queryString

With ?ids[]=foo, the resolver reports the messages of the Assert\All constraints instead of "This value should be of type int.".

The option keeps its existing trap: values are set as is, so it only helps for properties that can hold the string (mixed, array, or a docblock type on an untyped property). A property with a native int type still fails at the constructor or the setter, the same as it does for JSON today.

Checks run: ./phpunit src/Symfony/Component/Serializer (1403 tests, green) and ./phpunit src/Symfony/Component/HttpKernel (1677 tests, green; its resolver uses the csv path). The two new tests fail on 8.1 with the conversion exception. The scenario of the issue was also run end to end through RequestPayloadValueResolver: custom messages with the option, unchanged type message without it. No test was added to HttpKernel on purpose: its lowest-dependency job would run it against a released Serializer that does not have the fix.

@carsonbot carsonbot added this to the 8.1 milestone Aug 25, 2026
@nicolas-grekas
nicolas-grekas merged commit bf5c07f into symfony:8.1 Aug 25, 2026
13 checks passed
@nicolas-grekas
nicolas-grekas deleted the serializer-type-enforcement-opt-out branch August 25, 2026 13:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.