caelum / vraptor

Simple Java Web MVC Framework

Home Page:http://vraptor.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Json serialization include one child property

dtelaroli opened this issue · comments

I wanna include only the primary key from all classes.
The include method in json representation not accept include a child property directly.

e.g

result.use(json()).include("myObj.id").serialize();

if I include the root property, all properties will be serializeds, unnecessarily

I think that should be cool have this feature, generating more light jsons without excluding individuals properties.

What do you think? Is it viable?

Did you try?

result.use(json()).from(myObject).excludeAll().include("myObj.id").serialize();

I want to include all from root and id from parents

class MyObj {
   Long id;
   String name;
   MyOther myOther;
   ...
}

class MyOther{
   Long id;
   String description;
}

Preserves excludeAll the root properties?
There is excludeAll documentation?

I'm sorry, this method is not released yet. And the docs needs improvements to explain better how to use. I'll do this soon.

In your case, what's the expected json?

{"myObj": {"id":1, "name": "value for name", "myOther":{"id":1}}

I'll do tests to see if excludeAll() helps you.