[Serializer] Let DISABLE_TYPE_ENFORCEMENT keep strings that cannot be converted - #65640
#65640Merged
nicolas-grekas merged 1 commit intoAug 25, 2026
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
Merged
[Serializer] Let DISABLE_TYPE_ENFORCEMENT keep strings that cannot be converted#65640nicolas-grekas merged 1 commit intosymfony:8.1symfony/symfony:8.1from nicolas-grekas:serializer-type-enforcement-opt-outnicolas-grekas/symfony:serializer-type-enforcement-opt-outCopy head branch name to clipboard
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
For formats where every value is a string (XML, CSV, and the query string or form data mapped by
#[MapQueryString]and#[MapRequestPayload]),AbstractObjectNormalizerconverts the string to the declaredbool,intorfloat. When the conversion is impossible, it throws aNotNormalizableValueExceptionbefore it readsDISABLE_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 alist<int>property used to reach the validator, they now stop at the serializer, and the validator never runs.This PR makes
DISABLE_TYPE_ENFORCEMENTcover 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:With
?ids[]=foo, the resolver reports the messages of theAssert\Allconstraints 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 nativeinttype 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 throughRequestPayloadValueResolver: 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.