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

XML deserialization properties null when using default namespace #504

Closed
shabbyrobe opened this issue Oct 8, 2015 · 1 comment
Closed
Assignees

Comments

@shabbyrobe
Copy link

When I deserialize an XML document that uses a default namespace, none of the properties get set. I've tracked the problem down to https://github.com/schmittjoh/serializer/blob/master/src/JMS/Serializer/XmlDeserializationVisitor.php#L259 but I'm not entirely sure if it's me doing something wrong or not.

If it isn't my script, I'm happy to work up a fix if you'd like.

PHP version is 5.6.

bug.php:

<?php
namespace Pants
{
    class Test
    {
        private $name;

        public function getName()   { return $this->name; }
        public function setName($v) { $this->name = $v; }
    }
}

namespace
{
    require __DIR__.'/vendor/autoload.php';

    $serializer = JMS\Serializer\SerializerBuilder::create()
        ->addMetadataDir(__DIR__.'/resources', 'Pants')
        ->build();

    // works when using prefixes
    $xml = '
        <t:test xmlns:t="urn:pants.xsd">
            <t:name>HELLO</t:name>
        </t:test>
    ';
    var_dump($serializer->deserialize($xml, 'Pants\Test', 'xml'));

    // doesn't work when not using prefixes
    $xml = '
        <test xmlns="urn:pants.xsd">
            <name>HELLO</name>
        </test>
    ';
    var_dump($serializer->deserialize($xml, 'Pants\Test', 'xml'));
}

resources/Pants.yml:

Pants\Test:
    xml_root_name: Test
    xml_root_namespace: urn:pants.xsd

    properties:
        name:
            expose: true
            access_type: public_method
            serialized_name: name
            xml_element:
                namespace: 'urn:pants.xsd'
            accessor:
                getter: getName
                setter: setName
            type: string

Output:

class Pants\Test#58 (1) {
  private $name =>
  string(5) "HELLO"
}
class Pants\Test#58 (1) {
  private $name =>
  NULL
}
@goetas goetas self-assigned this Apr 24, 2017
@goetas
Copy link
Collaborator

goetas commented Apr 25, 2017

Sorry for the terribly long feedback loop. This issue has been already solved in 1.4, if the problem still occurs, eel free to comment it here, and I will re-open it again.

@goetas goetas closed this as completed Apr 25, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants