-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[Serializer] Support preserving array keys with XmlEncoder
#60228
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
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
72bae95 to
1c234b2
Compare
1c234b2 to
fbea2c7
Compare
<item> elements in XmlEncoder
<item> elements in XmlEncoderXmlEncoder
fbea2c7 to
d89d08f
Compare
nicolas-grekas
approved these changes
Sep 15, 2025
Member
nicolas-grekas
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I renamed the option as XmlEncoder::PRESERVE_NUMERIC_KEYS and fixed missing related changes.
fabpot
approved these changes
Sep 17, 2025
Member
|
Thank you @Deltachaos. |
javiereguiluz
added a commit
to symfony/symfony-docs
that referenced
this pull request
Sep 25, 2025
…er (dmytro-liashko-dev) This PR was merged into the 7.4 branch. Discussion ---------- [Serializer] Support preserving array keys with XmlEncoder This follows the issue #21388 which is related to the PR symfony/symfony#60228 Commits ------- 96802d1 [Serializer] Support preserving array keys with XmlEncoder
nicolas-grekas
added a commit
that referenced
this pull request
Sep 29, 2025
This PR was merged into the 7.4 branch. Discussion ---------- [Serializer] xml empty array encoding | Q | A | ------------- | --- | Branch? | 7.4 | Bug fix? | yes | New feature? | no <!-- if yes, also update src/**/CHANGELOG.md --> | Deprecations? | no <!-- if yes, also update UPGRADE-*.md and src/**/CHANGELOG.md --> | Issues | n/a | License | MIT This fixes a BC break introduced in #60228. At https://github.com/symfony/symfony/pull/60228/files#diff-b031dbb2186367839adfe20696612866da91513dd315f00ad6df23b5d38fca74R381 the condition change breaks encoding of an empty array: ```diff - if (ctype_digit(implode('', array_keys($data)))) { + if (!$preserveNumericKeys && null === array_find_key($data, static fn ($v, $k) => is_string($k))) { ``` Indeed, `array_find_key` on an empty array correctly finds no string keys and returns null, making the condition true. The previous version using `ctype_digit` was false. Commits ------- be51e2c [Serializer] xml empty array encoding
This was referenced Oct 27, 2025
Merged
Merged
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.
Feature: Add Support for preserving array keys as Child
<item>Elements in XML EncoderThis PR introduces a new option to the Symfony Serializer's
XmlEncoderthat allows indexed arrays to be encoded as<item>elements under a single parent element, rather than repeating the parent element for each array item.Motivation
Currently, encoding an array like:
produces the following XML:
This structure is not ideal when a clear container-child relationship is required, such as when interoperating with systems that expect such XML structures.
New Behavior
With the new
XmlEncoder::PRESERVE_NUMERIC_KEYSoption enabled, the same data now encodes to:Usage