title: Filtering entity fields dynamically in Spring Data rest json Response
body: <p>Hi I have a requirement to dynamically ignore entity fields in spring data rest response [I know they can be done in a static way by using @JsonIgnore annotation] ideally based on a spring security Role .The role part is still manageable but how to dynamically ignore fields in the json response is a challenge.
  After some analysis and the docs I think jackson is the way to go as spring data rest does provide jackson customization via jackson modules and mixins <a href="http://docs.spring.io/spring-data/rest/docs/current/reference/html/#customizing-sdr.custom-jackson-deserialization" rel="nofollow">http://docs.spring.io/spring-data/rest/docs/current/reference/html/#customizing-sdr.custom-jackson-deserialization</a> .</p>
  
  <p>So I think in jackson api it could be done via @jsonFilter and then suppling the same when the ObjectMapper write the object [more details here <a href="http://www.cowtowncoder.com/blog/archives/2011/09/entry_461.html]" rel="nofollow">http://www.cowtowncoder.com/blog/archives/2011/09/entry_461.html]</a> .</p>
  
  <p>But I am not sure how this could be wired up with Spring data rest (basically the part where I acan inject the filterprovider into spring data rest objectmapper).Let me know if anyone has tried this or someone from the Spring data team has insights .</p>
  
  <p>Will post an answer myself If I am able to achieve the same.</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>So I figured out that the way to implement custom filtering is through the jackson BeanSerializerModifier .Got great help from @cowtowncoder on twitter .Also helpful reference or holy grails for filtering with jackson <a href="http://www.cowtowncoder.com/blog/archives/2011/02/entry_443.html" rel="nofollow">http://www.cowtowncoder.com/blog/archives/2011/02/entry_443.html</a></p>