different json views for the same entity

2019-09-15 13:26发布

问题:

i am wondering How would you enable different json views of the same entity (example, public data and authenticated only, list views, full details, etc)?

in case if there are Jboss AS 7 + RestEasy or spring + jersey .

I am working on application which has to populate different data according to logged in user and its role.

Thanks

回答1:

This depends how you want to design you application.

The basic design for this kind of requirement is to use the session management to produce the data OR json for each request from the servers.When the request comes from a browser it has a unique session associated with all the request coming form the same browser.

  1. Once the user is logged in create a session for that request ( Means for that user) by putting that user in session or putting a boolean in session that user is logged in .

  2. So once the user and logged in boolean is set in request session, then every request coming from that browser will have those variables available.

  3. Then you can create you JSON based on user and logged in status by retrieving the sessions variables



回答2:

Below link might help

http://wiki.fasterxml.com/JacksonJsonViews

This has detailed explanation of how to create different views and apply them