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

Empty array removed from XML serialization #816

Closed
niabot opened this issue Aug 31, 2017 · 3 comments
Closed

Empty array removed from XML serialization #816

niabot opened this issue Aug 31, 2017 · 3 comments

Comments

@niabot
Copy link

niabot commented Aug 31, 2017

Q A
Bug report? yes
Feature request? no
BC Break report? no
RFC? no

Steps required to reproduce the problem

If i serialize the following following class (i removed the other properties) then the roles property is removed from the XML. But it stays if i serialize to JSON or YAML.

namespace app\controllers\login;

use JMS\Serializer\Annotation as SE;

/**
 * @SE\XmlRoot("loginResponse")
 */
class LoginResponseObject {
    	/**
	 * @SE\Type("array<string>")
	 * @SE\XmlList(inline=false,entry="role")
	 */
	public $roles = [];
}

As JSON i get:

{
  "roles": []
}

But as XML i only get:

<?xml version="1.0" encoding="UTF-8"?>
<loginResponse>
</loginResponse>

I would expect the following output, which would match the results for JSON and YAML:

<?xml version="1.0" encoding="UTF-8"?>
<loginResponse>
    <roles></roles>
</loginResponse>
@goetas
Copy link
Collaborator

goetas commented Aug 31, 2017

see

public $skipWhenEmpty = true;

@goetas goetas closed this as completed Aug 31, 2017
@niabot
Copy link
Author

niabot commented Aug 31, 2017

This property should be added to the annotation documentation. I totally missed it.

@goetas
Copy link
Collaborator

goetas commented Aug 31, 2017

PR are welcome

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