Skip to content
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

[Serializer] fix denormalization of xml-values to objects when no xml-attributes are specified #34825

Closed
wants to merge 1 commit into from

Conversation

mkrauser
Copy link
Contributor

@mkrauser mkrauser commented Dec 4, 2019

Q A
Branch? 4.3
Bug fix? yes
New feature? no
Deprecations? no
Tickets Fix #32114
License MIT
Doc PR

When deserializing an XML-Node like this to an object, everything works as expected:

<some-element optionalAttribute="foo">bar</some-element>

But if all attributes are optional and missing from the node, the deserialization fails

<some-element>bar</some-element>

The serializer handles XML-Attributes by prefixing them with '@' and node-data are handled with the special key '#'. But this key is only used, when attributes are present (see XmlEncoder.php#L175-185).

I choose to fix this within the denormalize-function of the AbstractObjectNormalizer. Handling it within the NameConverter would also be possible, but the NameConverter's don't know the source-format.

@mkrauser mkrauser changed the title [Serializer] fix denormalization of xml-values to objects without attributes [Serializer] fix denormalization of xml-values to objects when no xml-attributes are specified Dec 4, 2019
@nicolas-grekas nicolas-grekas added this to the 4.3 milestone Dec 6, 2019
@dunglas
Copy link
Member

dunglas commented Jan 22, 2020

Shouldn't this be handled in the XML decoder directly?

@mkrauser
Copy link
Contributor Author

mkrauser commented Jan 22, 2020

Shouldn't this be handled in the XML decoder directly?

@dunglas Wouldn't this also mean, that we always serialize and deserialize node-values using the '#'-key? Because the decoder does not know about the Model. IMHO this would be a big BC-break.

@nicolas-grekas nicolas-grekas modified the milestones: 4.3, 4.4 Feb 1, 2020
@fabpot
Copy link
Member

fabpot commented Sep 13, 2020

@dunglas Can you have a look at @mkrauser question?

@nicolas-grekas
Copy link
Member

Closing as this staled.

Please submit again when you can!

fabpot added a commit that referenced this pull request Apr 5, 2024
…rld)

This PR was merged into the 5.4 branch.

Discussion
----------

[Serializer] Fix XML scalar to object denormalization

| Q             | A
| ------------- | ---
| Branch?       | 5.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Issues        | Fix #32114 #34579
| License       | MIT

Another approach to #34825

Commits
-------

6fe892f [Serializer] Fix XML scalar to object denormalization
symfony-splitter pushed a commit to symfony/serializer that referenced this pull request Apr 5, 2024
…rld)

This PR was merged into the 5.4 branch.

Discussion
----------

[Serializer] Fix XML scalar to object denormalization

| Q             | A
| ------------- | ---
| Branch?       | 5.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Issues        | Fix #32114 #34579
| License       | MIT

Another approach to symfony/symfony#34825

Commits
-------

6fe892f035 [Serializer] Fix XML scalar to object denormalization
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.

None yet

5 participants