title: Jackson field serialization based on another field
body: <p>Considering I have such model:</p>
  
  <pre><code>public class Model {
  
      private String master;
      private Integer slave;
      private String notImportantField1;
      private String notImportantField2;
      private String notImportantField3;
      private String notImportantField4;
      private String notImportantField5;
      private String notImportantField6;
      private String notImportantField7;
      private String notImportantField8;
      private String notImportantField9;
      private String notImportantField10;
      private String notImportantField11;
      private String notImportantField12;
      private String notImportantField13;
      private String notImportantField14;
      private String notImportantField15;
  
      public void setMaster(String master) {
          this.master = master;
      };
      public String getMaster() {
          return master;
      };
  
      public void setSlave(Integer slave) {
          this.slave = slave;
      };
      public Integer getSlave() {
          return slave;
      };
  
      /** 
      * Similar getters/setters for other fields
      */
  }
  </code></pre>
  
  <p>What I want is that after serialization value of "slave" field should be different type depending on "master" field value. For example, having condition:</p>
  
  <pre><code>masterCondition = master.equals("string");
  </code></pre>
  
  <p>If "masterCondition" is true the result JSON is:</p>
  
  <pre><code>{
      "master": "master_value",
      "slave": "1234567890",
      **And all other fields as they are.**
  }
  </code></pre>
  
  <p>As you can see, we have string value in "slave" field.
  If "masterCondition" is false the result JSON is:</p>
  
  <pre><code>{
      "master": "master_value",
      "slave": 1234567890,
      **And all other fields as they are.**
  }
  </code></pre>
  
  <p>As you can see, in the second response we have integer value in "slave" field.</p>
  
  <p>I tried to use class-level serializer and it works for me but but these approach produce a lot of boilerplate code for "notImportantFields" and not-null checking.</p>
  
  <p>Also I tried to use ContextualSerializer but it looks that there is no way to get value of another field if I use such serializer on field-level.
  Is there a way to implement such behavior without boilerplate code?
  Thanks!</p>