title: How to write a conditional @JsonIgnore
body: <p>I need to write an annotation that will ignore certain fields, but only in certain contexts.  I would love to be able to just inject a context value into ObjectMapper, but I can't find anything.  I need the serializing to work exactly the same using the default ObjectMapper.  But in a certain context, my annotation would take special action (in my case, the equivalent of <code>@JsonIgnore</code>).
  I don't think filters would work for me, because it doesn't allow the default case to continue to work.  I also don't want to skip fields based on the property name.  I want any object to be able to be annotated with <code>@MyJsonIgnore</code></p>
  <p>Example</p>
  <pre><code>public class MyObject {
    private String field1 = &quot;value1&quot;;
    @MyJsonIgnore
    private String field2 = &quot;value2&quot;;
  </code></pre>
  <p>Normally, this would get serialized like this</p>
  <pre><code>ObjectMapper mapper = new ObjectMapper();
  mapper.writeValueAsString(new MyObject());
  {
     &quot;field1&quot;: &quot;value1&quot;,
     &quot;field2&quot;: &quot;value2&quot;
  }
  </code></pre>
  <p>But in my special use case, I would have</p>
  <pre><code>ObjectMapper mapper = new ObjectMapper();
  mapper.setMagicalContext(&quot;context&quot;);
  mapper.writeValueAsString(new MyObject());
  {
     &quot;field1&quot;: &quot;value1&quot;
  }
  </code></pre>
  <p><code>field2</code> would not get serialized since it has the <code>@MyJsonIgnore</code> annotation.</p>
  <p>Is there anything that would do this?</p>