Resthub-mongo: limit fields for server->client

47 views
Skip to first unread message

Konstantin

unread,
Jan 18, 2013, 8:17:18 AM1/18/13
to resth...@googlegroups.com
I have mongo objects with 20+ fields.I use basic crud controller (public class SampleController extends RepositoryBasedRestController<Sample, String, SampleRepository>)
Is there easy way to limit fields that were send from server to client (e.g. specify 3 fields)? If not, what will be right way to implement? Override controller methods and add list of fields as param to requests?
Ideally if i could specify them from client, when making request. 

Konstantin

unread,
Jan 18, 2013, 8:41:14 AM1/18/13
to resth...@googlegroups.com
just small addition:
At server side my model objects extend hashmap, so i could access all fields in service layer. But client need only limited set of fields. 

Sébastien Deleuze

unread,
Jan 18, 2013, 8:44:01 AM1/18/13
to resth...@googlegroups.com
Hi,

You can't do this with RESThub 2.0, but with 2.1-SNAPSHOT you can thnaks to a new functionnality called custom JSON views.

RESThub 2.1-SNAPSHOT artifacts are available from https://oss.sonatype.org/content/repositories/snapshots/org/resthub
Custom JSON views documentation is available at http://resthub.org/snapshot/spring-stack.html#custom-json-views

Feel free to send feedbacks about this functionnality.






--
 
 
 

Konstantin

unread,
Jan 18, 2013, 8:53:46 AM1/18/13
to resth...@googlegroups.com, s...@deleuze.fr
Yes, i'm aware of that feature, but then i need to specify in model all fields.

What i'm looking is more like: 
@RequestMapping("{id}")
public @ResponseBody Book getSummary(@PathVariable("id") Integer id, @RequestParam("fields") List<String> fieldList)
{
    //return map with specified fields only
}
But it look like i will have to implement that myself :)

Sébastien Deleuze

unread,
Jan 18, 2013, 9:11:59 AM1/18/13
to resth...@googlegroups.com
Ok understood it is currently not managed.
It could be a really powerful feature, feel free to send us a pullrequest if you succeed, we will review and if OK integrate it in RESThub 2.1 !


--
 
 
 

Reply all
Reply to author
Forward
0 new messages