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 doesn't serialize nested objects correctly #317

Closed
ghost opened this issue Aug 16, 2013 · 2 comments
Closed

Serializer doesn't serialize nested objects correctly #317

ghost opened this issue Aug 16, 2013 · 2 comments

Comments

@ghost
Copy link

ghost commented Aug 16, 2013

{
    "id": 51,
    "name": "Nathan",
    "car": {
        "id": 4,
        "name": "My Car",
        "passengers": [
            {
                "id": 8,
                "user": {
                    "id": 55,
                    "name": "User1"
                }
            },
            {
                "id": 9
            },
            {
                "id": 10,
                "user": {
                    "id": 41,
                    "name": "User1"
                }
            }
        ]
    }
}

I'm attempting to serialize a user object, this user object has a relation to 'car' which holds other 'user' entities. The problem is that id 9 is myself, and it will not print the whole user out.

If I turn on displaying null values, 'user' is set to null, like so:

            {
                "id": 9,
                "user": null
            }
@ghost
Copy link
Author

ghost commented Aug 17, 2013

I've notices if I

clone $this->getUser()

it outputs my JSON correctly.

@schmittjoh
Copy link
Owner

The serializer automatically prevents endless recursion and skips over all objects which it is currently visiting.

If you want your user object to be visited twice (as root and as part of a nested collection), then cloning at the moment is the only way to achieve that.

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

No branches or pull requests

1 participant