If you use Jackson (a great JSON lib – kind of the standard for Java I believe), you may use the
@View annotation to filter what you want in the resulting object.
I understand that you want something dynamic so it’s a bit more complicated. You will find what you are looking for here: http://www.cowtowncoder.com/blog/archives/2011/02/entry_443.html (look at 6. Fully dynamic filtering:
I would be interested in the solution you will find.