Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>From your architecture, I am guessing that you have the security filters setup already (I believe it's called OncePerRequestFilter in Spring?). The way I have approached this in the past is use my security filters to get the "Role" of the client (assuming you can have roles assigned for each client which map to specific permissions/restrictions on each resource object). Now based on the "Role" I have custom JSON serializer/deserializer strategies (I used GSON for this inclusion/exclusion type adapters. You can read more <a href="https://stackoverflow.com/questions/11271375/gson-custom-seralizer-for-one-variable-of-many-in-an-object-using-typeadapter">here (Gson custom seralizer for one variable (of many) in an object using TypeAdapter)</a> ) that will take care of what resource fields should/should not be populated/serialized. This way, you will continue to use the same resource object and TypeAdapter for each resource object which will determine the serialization/deserialization of the resource object based on the role of the client.</p> <p>One more idea that comes to my mind is method interceptors (Spring AOP). Although I have never tried it with method interceptors, I think it should still work in the sense that you will intercept the method right BEFORE it returns (and after the business logic is done) and look at the role of the client making the request. Based on that role, you can determine what fields to null out (most serializers (atleast gson) do not serialize null fields) and not serialize, before converting it to json (or whatever your return type might be) and sending it over to the client</p> <p>I hope this helps. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload