Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

@XmlRoot annotation no longer working #131

Closed
chadl opened this issue Aug 1, 2013 · 3 comments
Closed

@XmlRoot annotation no longer working #131

chadl opened this issue Aug 1, 2013 · 3 comments

Comments

@chadl
Copy link

chadl commented Aug 1, 2013

@schmittjoh ::: I have a similar problem to the one reported over here(schmittjoh/JMSSerializerBundle#262), but this problem only arose once I upgraded my symfony from 2.0.9 (I know, we were lagging behind) to a slightly newer 2.0.23.

I had some simple serializer tests, like this:

use JMS\Serializer\Annotation\XmlRoot;

/**
 * @XmlRoot("root")
 */
class Foo {
   protected $name ="Chad";
}

$serializer = SerializerBuilder::create()->build();
$xml = $serializer->serialize(new Foo(), 'xml');

The resulting XML looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<result>
  <name><![CDATA[Chad]]></name>
</result>

Prior to the 2.0.23 upgrade, this code would produce:

<?xml version="1.0" encoding="UTF-8"?>
<root>
  <name><![CDATA[Chad]]></name>
</root>

Interested to hear your thoughts on this one, and perhaps you've seen this behaviour before and can point me to what may be wrong here?

Thanks!

@Tobion
Copy link
Contributor

Tobion commented Nov 30, 2013

It works on a recent version. I'd suggest you upgrade. Btw, symfony 2.0 is not maintained anymore. So not sure if we want to spend resources on this issue.

@chadl
Copy link
Author

chadl commented Nov 30, 2013

Right... chalk this up as a wont-fix then.

We are in the process of upgrading our Symfony install, so we should be fine with serializer once we have completed this upgrade.

Thanks!

@chadl chadl closed this as completed Nov 30, 2013
@emottet
Copy link

emottet commented Jan 27, 2015

Hi,
I have a similar problem with symfony 2.6, where I implement web services using FOSRESTBundle and JMSSerializerBundle.
I don't know if i'm doing things the right way but here is what i've done.

I have a config\serializer\Entity.Request.yml file with the following information:

Tvjp\RequestBundle\Entity\Request:
    exclusion_policy: ALL
    xml_root_name: request
    properties:
        id:
            expose: true
            type: integer
        label:
            expose: true
            type: string
        issuer:
            expose: true
            type: string

When i try to access to a single request, this is what i got:
- in json : {"id":23,"label":"test label ws post","issuer":"test issuer ws post"}
- in XML :

<result>
    <id>23</id>
    <label><![CDATA[ test label ws post ]]></label>
    <issuer><![CDATA[ test issuer ws post ]]></issuer>
</result>

I can't manage to have a root element named request eventhough i put xml_root_name: request in the configuration file.
Am I doing something wrond here ?

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants