title: Jackson @JsonIgnore fields based on spring security roles
body: <p>In all of my Spring REST Web application, I have a lot of domain objects and DTOs.</p>
  
  <p>I need to filter some domain object or DTOs fields based on the spring security roles of the user who makes the request. I want Jackson to filter the output JSON to allow/disallow specific class fields to be serialized , based on the Spring GrantedAuthorities roles of the user who tries to access the resource.</p>
  
  <p>I can't create new DTO for every different view combination because it would be a mess.</p>
  
  <p>I have found this solution :<br>
  <a href="https://stackoverflow.com/questions/17276081/spring-3-2-filtering-jackson-json-output-based-on-spring-security-role">Spring 3.2: Filtering Jackson JSON output based on Spring Security role</a><br>
  But it doesn't work, the filter is only applied once, when the first user logins. Then all the other users obtain the same filtering , no matter what their role is.</p>
  
  <p>I cannot explain my problem better than Ray Holland on this blog post :<br>
  <a href="http://jackson-users.ning.com/forum/topics/jackson-custom-serialization" rel="nofollow noreferrer">http://jackson-users.ning.com/forum/topics/jackson-custom-serialization</a><br>
  This is the exact same problem I'm trying to solve for a few days.  </p>
  
  <p>I couldn't find a clean way to do that so far.</p>