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

Exclusion of inner field of the same type does not work #550

Open
wagnerfrancisco opened this issue Jul 16, 2013 · 2 comments
Open

Exclusion of inner field of the same type does not work #550

wagnerfrancisco opened this issue Jul 16, 2013 · 2 comments

Comments

@wagnerfrancisco
Copy link

It's better to explain with this example:

Given an object of type User that has an attribute also of type User:

class User {
   String name;
   User user;
}

If I try to remove not directly the user attribute, but the user of the inner user, the generated json does not have any references to user. For instance:

result(json()).withoutRoot().from(user).exclude("user.user").serialize();

I expected to have something like:

{ "name": "Wagner", "user": {} }

But I actually have:

{ "name": "Wagner" }

Vraptor removes any references to user, not just the requested one.

@lucascs
Copy link
Member

lucascs commented Jul 16, 2013

I think the intended exclusion is just .exclude("user"), right?

@wagnerfrancisco
Copy link
Author

No. Actually my goal was to exclude just the "user of the user". I have this:

User a = new User();
User b = new User();
b.setUser(a);
User c = new User();
c.setUser(b);

If I try to serialize "user c", in recursive mode, it would serialize the information of "user b" and indirectly of "user a" too. If I want to remove the information just of the "user a", I think it's impossible.

I just had a look at ExclusionStrategy interface of Gson, but apparently there isn't enough context there to do this kind of exclusion. Maybe it's better to do this directly in the app.

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

2 participants