title: Serialization and Deserialization with Jackson: how to programmatically ignore fields?
body: <p>I'm using Jackson to serialize and deserialize objects. The problem is that sometimes I want to show a field and sometimes not.</p>
  
  <p>Actually I'm using the @JsonIgnore to avoid the printing of the property when I don't need it. When I need it I'm disabling the Property through </p>
  
  <pre><code>mapper.getSerializationConfig().disable(SerializationConfig.Feature.USE_ANNOTATIONS);
  </code></pre>
  
  <p>but this will disable also other annotations that I need.</p>
  
  <p>How can I get the result that I need? Using Views? Any example?</p>
  
  <p>A little pojo to understand what I want:</p>
  
  <pre><code>class User {
  private String username;
  @JsonIgnore    
  private String password;    
      // getter setter
  }
  
  
  writeToDB() {
  mapper.getSerializationConfig().disable(SerializationConfig.Feature.USE_ANNOTATIONS);
  mapper.writeValueAsString(user);
  }
  </code></pre>
  
  <p>and through the REST API you can get the username without the password (thanks to the JsonIgnore)</p>