title: Jackson: how to prevent field serialization (while keeping deserialization)
body: <p>I'd like to go further on what <a href="https://stackoverflow.com/questions/9112900/jackson-how-to-prevent-field-serialization">this question</a> was about, I've been roaming SO for a solid hour now without finding anything.</p>
  
  <p>Basically, what I'm trying to do is having a property properly instanciated through Jackson internal reflection algorithm during deserialization but having this same property <strong>not</strong> serialized when it comes to serialization.</p>
  
  <p>I know about <code>@JsonIgnore</code> and <code>@JsonIgnoreProperties</code> but apparently I can't seem to use them right : either my property is correctly deserialized when I feed Jackson a proper map of properties but it also appears in the serialized results, either (when using <code>@JsonIgnore</code>) it is not serialized (which is wanted) but also not deserialized (not wanted).</p>
  
  <p>Example :</p>
  
  <pre><code>public class Foo {
  
      /* This is the property I want to be instanciated by Jackson upon deserialization
       * but not serialized upon serialization
       */
      private final Object bar = null;
  
      public Object getBar() {
          return bar;
      }
  }
  </code></pre>
  
  <p>To make things worse, as you can see, the property is final (this is why I'm keen on using Jackson reflection ability upon <code>Foo</code> instanciation through deserialization). I've read on potential solution about annotating the setter and the getter differently but I'd like to keep this property final if possible. <em>If not possible</em>, I'd settle for a non-final property.</p>
  
  <p>I would appreciate answers not suggesting custom serializer/deserializer, my code base is currently free of such and if the solution could be of minimal impact, that would be perfect. Again, I'm no Jackson expert so if what I'm asking is not possible I'll obviously accept alternative answers.</p>
  
  <p>I've also read <a href="https://github.com/FasterXML/jackson-databind/issues/95" rel="nofollow noreferrer">this thread on github</a> but none of the suggested ways of implementation have actually been implemented at the moment.</p>
  
  <p>Thanks</p>
  
  <hr>
  
  <p>EDIT : to make things clearer</p>
  
  <pre><code>public class Foo {
  
      private final String bar = null;
  
      public String getBar() {
          return bar;
      }
  
      @Override
      public String toString() {
          return bar;
      }
  }
  
  
  public void testMethod() throws IOException {
          String json = "{\"bar\":\"Value\"}";
          ObjectMapper mapper = new ObjectMapper();
          Foo foo = mapper.readValue(json, Foo.class);
          System.out.println(foo); // should have a bar property set to "Value"
          System.out.println(mapper.writeValueAsString(foo)); // should return an empty JSON object
  }
  </code></pre>