From Dynamic Selection Of JsonView in Spring MVC Controller, I understand that you can annotate controllers using @JsonView(...)
and also return MappingJacksonValue
with the serialization view specified from within the method. Is there a way to globally & dynamically select the serialization view based on the currently logged-in principal? I couldn't use the solution from the linked article because the object, that I wanted to serialized with dynamically different views, is nested inside a list.
To be a little more specific, my use case is: a logged-in user can view other user account details, but cannot view specific attributes like e-mail, circle of friends, etc. unless they are viewing their own account or are already friends with that user. I want to globally be sure that the currently logged-in user cannot view attributes that they are not entitled to by the other user.
Thank you in advance!