10000 [Yaml] Yaml::dump() encodes empty array as empty object · Issue #15781 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Yaml] Yaml::dump() encodes empty array as empty object #15781

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

Closed
johnknl opened this issue Sep 14, 2015 · 7 comments
Closed

[Yaml] Yaml::dump() encodes empty array as empty object #15781

johnknl opened this issue Sep 14, 2015 · 7 comments
Labels

Comments

@johnknl
Copy link
johnknl commented Sep 14, 2015

See johnknl/swagger-bundle#18

@fabpot
Copy link
Member
fabpot commented Sep 14, 2015

Have a look at the signature and the last argument.

@fabpot fabpot closed this as completed Sep 14, 2015
@johnknl
Copy link
Author
johnknl commented Sep 14, 2015

@fabpot I did, and I followed it to Inline::dump()#106, where it checks if the value is an object, which it is not. If it is, and that last argument ($objectSupport) is set to TRUE instead of the default FALSE, it will serialize the object and prefix it with '!!php/object:`. Clearly this is not what is happening.

Also my assertion $this->assertNotRegExp('/\: \{ \}/', $content); will still fail, even with the argument set to FALSE ($yaml = Yaml::dump($data, 10, 2, false, true);).

I am starting to doubt myself a little bit here, but right now I think this should be reopened.

@xabbuh xabbuh added the Yaml label Sep 30, 2015
@xabbuh
Copy link
Member
xabbuh commented Sep 30, 2015

@kleijnweb see also #9870

@xabbuh
Copy link
Member
xabbuh commented Feb 8, 2016

see #17728 for the implementation

fabpot added a commit that referenced this issue Feb 28, 2016
This PR was merged into the 3.1-dev branch.

Discussion
----------

[Yaml] add option to dump objects as maps

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #9870, #12860, #15781, #15937, #16266
| License       | MIT
| Doc PR        | TODO

Commits
-------

3941d2e [Yaml] add option to dump objects as maps
@didoda
Copy link
didoda commented May 9, 2017
$yaml = ['test' => []];
$result = Yaml::dump($yaml, 2, 4, Yaml::DUMP_OBJECT_AS_MAP);
echo $result; // => "test: {  }"

it seems to me that "empty array" returns "empty object"; how can I get "test: [ ]" as result (empty array)?

@xabbuh
Copy link
Member
xabbuh commented May 9, 2017

@didoda You need to use the DUMP_EMPTY_ARRAY_AS_SEQUENCE flag which will be available in Symfony 3.3 (see #21471).

@didoda
Copy link
didoda commented May 10, 2017

@xabbuh , thanks for the reply. I will use DUMP_EMPTY_ARRAY_AS_SEQUENCE when available ;)

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

No branches or pull requests

4 participants
0