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

Configure whether serializing empty array. #124

Closed
Tobion opened this issue Jul 19, 2013 · 6 comments
Closed

Configure whether serializing empty array. #124

Tobion opened this issue Jul 19, 2013 · 6 comments

Comments

@Tobion
Copy link
Contributor

Tobion commented Jul 19, 2013

The serializer currently allows to configure whether to serialize null values.
I think one more option is necessary: to configure whether to serialize empty arrays/strings. Otherwise it's a little incosistent that null values are not serialized but empty arrays are which is currently the case. But both basically mean the same: there is no information available.

So I'd suggest to add a method setSerializeEmpty which when passed false, will not serialize empty arrays (array()) and empty strings (''). So it does not have to do with the php empty() function because we want to serialize 0 and false.

@vkartaviy
Copy link

👍

@Tobion
Copy link
Contributor Author

Tobion commented Nov 8, 2013

Also there is any inconsistency in serializing arrays:

@Serializer\Type("array<MyModel>")
public $attributes;

is serialized in JSON as empty array attributes: [] even though it's null.

Whereas @Serializer\Type("array") would not serialize the property because it's null.

@schmittjoh
Copy link
Owner

That seems like a bug. Are you sure this is the only difference?

@Tobion
Copy link
Contributor Author

Tobion commented Nov 8, 2013

I haven't tried the deserialization but from serialization it seems to be the only difference.

@goetas
Copy link
Collaborator

goetas commented Apr 24, 2017

Currently works for the XML visitor

public $skipWhenEmpty = true;

@goetas
Copy link
Collaborator

goetas commented May 10, 2017

fixed in #757

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

No branches or pull requests

4 participants