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

Use namespace from bottom of object stack #718

Closed
wants to merge 1 commit into from

Conversation

RLasinski
Copy link

I encountered problems with unserializing xml lists in xml lists with a default namespace from the root element.
The cause is, that you use the top element of the stack (newest one) not the bottom element (root).

I also added a test which fails with the previous implementation.

@goetas goetas self-assigned this Mar 6, 2017
@@ -454,7 +454,7 @@ private function addNamespaceAttributes(ClassMetadata $metadata, \DOMElement $el

private function createElement($tagName, $namespace = null)
{
if (null === $namespace) {
if (null === $namespace || $this->document->isDefaultNamespace($namespace)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not always true.

elements should be created in their namespace, if they belong to one. then the dom parser will take care of converting it into the correct xml reppresentation

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what you are trying to solve, i tried it with #644

@@ -295,7 +295,7 @@ public function visitProperty(PropertyMetadata $metadata, $object, Context $cont
if (null !== $metadata->xmlNamespace) {
$element = $this->createElement($elementName, $metadata->xmlNamespace);
} else {
$defaultNamespace = $this->getClassDefaultNamespace($this->objectMetadataStack->top());
$defaultNamespace = $this->getClassDefaultNamespace($this->objectMetadataStack->bottom());
Copy link
Collaborator

@goetas goetas Mar 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

your tests are not covering this line, running

vendor/bin/phpunit --filter=testObjectWithNamespacesAndListInList this line is never executed

@goetas
Copy link
Collaborator

goetas commented Mar 10, 2017

can you also rebase your PR ?

@goetas
Copy link
Collaborator

goetas commented Mar 10, 2017

I went a bit deeper in the analysis. Just add

@XmlNamespace(uri="http://example.com/namespace") on the JMS\Serializer\Tests\Fixtures\ObjectList class and your code will work.

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