Skip to content

[Serializer] Legacy TODO in XmlEncoder regarding root node name during decoding #61441

@mttsch

Description

@mttsch

Symfony version(s) affected

7.4

Description

XmlEncoder::decode() contains a very old TODO (> 10 years old) about the root node name:

// todo: throw an exception if the root node name is not correctly configured (bc)

While I wanted to deal with it and directly create a PR, I first want to gather feedback.

  1. I think there is code missing to catch if !$rootNode is true at this point (though the test case I wrote is a bit artificial but the previous loop still allows for it).
  2. At that time, when the TODO was added, $rootNodeName already existed thus I assume that the TODO was to throw an exception if the found root node does not match the configured root node name.

At the moment, the root node name is only used for encoding and I am doubt whether a BC break for 8.0 to resolve this TODO and also validate that the root node name matches the configured root node name brings any benefit.

How to reproduce

Look at

// todo: throw an exception if the root node name is not correctly configured (bc)

Possible Solution

  1. Add an additional check if !$rootNode (Would throw a NotEncodableValueException instead of generic exception with Call to a member function hasChildNodes() on null.) (I think that this can be done in 7.4, not only at 8.0?)
  2. Remove the TODO.
  3. Update documentation https://symfony.com/doc/current/serializer/encoders.html#the-xmlencoder-context-options to mention that the root node name option is only used for encoding.

Additional Context

No response

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