different json views for the same entity

偶尔善良 提交于 2019-12-25 01:50:50

问题


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



来源:https://stackoverflow.com/questions/16218164/different-json-views-for-the-same-entity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!