Skip to content

Manage empty array for serializer #510

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

Merged
merged 1 commit into from
Oct 27, 2015

Conversation

soullivaneuh
Copy link
Contributor

Fixes #183.
Fixes #124.

Actually, empty array would produce this:

parameters:
    phonenumber:

This is not correct. Furthermore, if you parse it with JMS or Symfony Yaml component, you will got null that is not the expected return.

With this PR, you will have this:

parameters:
    phonenumber: []

@stof
Copy link
Contributor

stof commented Oct 19, 2015

A test is needed to prevent regressions

@soullivaneuh
Copy link
Contributor Author

A test is needed to prevent regressions

I was looking for it but I don't know how to manage tests files.

Look at the test classes for yml, I don't know how to put the expected result to assert. Any clue?

@stof
Copy link
Contributor

stof commented Oct 19, 2015

Well, there is a hash_empty test (the test itself using it is at https://github.com/schmittjoh/serializer/blob/master/tests/JMS/Serializer/Tests/Serializer/BaseSerializationTest.php#L764). We just need a similar test for empty arrays

@soullivaneuh soullivaneuh changed the title Fix not written empty arrays on Yaml Manage empty array for serializer Oct 20, 2015
@soullivaneuh
Copy link
Contributor Author

Ok so I have to manage all file formats. Will work on it.

Actually, I got hard to understand phpunit errors.

@soullivaneuh
Copy link
Contributor Author

Well, I got this error on master too. Not related.

For me, this PR is ready to merge.

ping @schmittjoh

@soullivaneuh soullivaneuh mentioned this pull request Oct 20, 2015
@soullivaneuh
Copy link
Contributor Author

ping @schmittjoh

Could you please take a look? This issue is quite annoying, a quick patch is needed IMHO.

@gallart
Copy link

gallart commented Oct 26, 2015

👍

@@ -111,6 +111,11 @@ public function visitArray($data, array $type, Context $context)
->rtrim(false)
->writeln(' {}')
;
} elseif (0 === count($data)) {
Copy link
Owner

Choose a reason for hiding this comment

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

Can you change this to empty($data) if we specifically check for 0.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure empty($data) is the good way. We check for an empty array.

All another empty values should have ~ and not [].

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh I say something wrong, we are on visitArray. Will modify it.

@soullivaneuh
Copy link
Contributor Author

@schmittjoh Review corrected.

schmittjoh added a commit that referenced this pull request Oct 27, 2015
@schmittjoh schmittjoh merged commit fe13a1f into schmittjoh:master Oct 27, 2015
@soullivaneuh soullivaneuh deleted the yaml-empty-array branch October 27, 2015 10:09
@Tobion
Copy link
Contributor

Tobion commented Oct 27, 2015

How does this PR fix #124? I don't see it.

@schmittjoh
Copy link
Owner

Yes, that seems unrelated, but seems to have been auto-closed.

@soullivaneuh
Copy link
Contributor Author

@Tobion @schmittjoh My bad, I was thinking it was related.

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

Successfully merging this pull request may close these issues.

5 participants