0

When I'm seralize array I've got something like this:

{"0":{"id":1,"name":"Kowalscy","familyMembers":[{"id":1,"familyMemberType":1,"user":{},"name":"Pawel","isAdmin":true,"notes":[],"email":""},{"id":2,"familyMemberType":2,"user":{},"name":"Mama Koper","isAdmin":false,"notes":[],"email":""}],"children":[]},
"1":{"id":2,"name":"Spiochy","familyMembers":[{"id":3,"familyMemberType":2,"user":{},"name":"Test Nowak","isAdmin":false,"notes":[],"email":""}],"children":[]}, .....

But I have problem with deseralization that array using JSON, I think that it should look like:

[{object}, {object}]

Is there way to change that?

Here is my code from symfony2

$result = $serializer->serialize($families, 'json',SerializationContext::create()->setGroups(array('getFamilies')));

EDIT: I've found that "getArrayResult()" returns array, but it doesn't contain my relation entity

user1483208
  • 385
  • 5
  • 24

1 Answers1

1

From memory, it is a bad practice to have an array as top level in json.

What are "top level JSON arrays" and why are they a security risk?

Moreother, if you use array, you lost the ids of your objects. So it is normal that you lost relations.

Community
  • 1
  • 1
Alcalyn
  • 1,531
  • 14
  • 25