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

[Serializer] Serialization of empty ArrayCollection to JSON returns '{}' instead '[]' #37061

Closed
yauhenko opened this issue Jun 2, 2020 · 4 comments

Comments

@yauhenko
Copy link

yauhenko commented Jun 2, 2020

Symfony version(s) affected: 5.0.9, 5.1.0

Description
Entity User

class User implements UserInterface {

	/**
	 * @ORM\Id()
	 * @ORM\GeneratedValue()
	 * @ORM\Column(type="integer", options={"unsigned": true})
	 * @Groups("main")
	 */
	private int $id;
       // ...
	/**
	 * @ORM\ManyToMany(targetEntity=Department::class)
	 * @ORM\JoinColumn(onDelete="CASCADE")
	 * @Groups("main")
	 */
	private $departments;

My controller

	public function getUser(User $id) {
            return $this->json($user, 200, [], ['groups' => ['main']);
	}

Expected:

{
    "id": 2,
   // ...
    "departments": []
  }

Actual result:

{
    "id": 2,
   // ...
    "departments": {}
  }

How to reproduce
Just upgraded symfony/serializer to 5.0.9

@yauhenko yauhenko added the Bug label Jun 2, 2020
@yauhenko yauhenko changed the title Serialization of empty ArrayCollection to JSON returns '{}' instead '[]' [Serializer] Serialization of empty ArrayCollection to JSON returns '{}' instead '[]' Jun 2, 2020
@yceruto
Copy link
Member

yceruto commented Jun 2, 2020

Duplicated of #37041? and already fixed in #37049.

Thanks for reporting it !

@SergeyYesin
Copy link

This thing is not yet fixed in 5.0 and 5.1 branches.

@guillaumesmo
Copy link
Contributor

This thing is not yet fixed in 5.0 and 5.1 branches.

it will be in the next patch releases (4.4.10, 5.0.10 and 5.1.1) usually at the end of the month

@arisrais
Copy link

arisrais commented Jun 9, 2020

Thanks, I am waiting for it. I will bypass serializer v4.4.9 (my CI is down)

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

7 participants