title: Jackson serialization: Ignore uninitialised int
body: <p>Now first off, I've read some other answers on this site and others about jackson serialisation but they all provide methods for ignoring <code>null</code> fields. In Java, however, <code>int</code> cannot be <code>null</code>.</p>
  
  <p>I am trying to <code>ObjectMap</code> a java object to convert to <code>Json</code> but to ignore any <code>null</code> fields. This works for strings but <code>int</code>s end up taking on a value of <code>0</code> if uninitialised, and since <code>0</code> is not <code>null</code> the field is not ignored.</p>
  
  <pre><code>    private ObjectWriter mapper = new ObjectMapper().writer();
      private myClass data = new myClass(); //class contains a string and int variable
      data.setNumber(someInt); //set values
      data.setString(someString);
  
      String Json = mapper.writeValueAsString(data);
  </code></pre>
  
  <p>Can anyone shed some light on this please?</p>
  
  <p>EDIT: To clarify, I have tried using the <code>Integer</code> class as the data type but causes the conversion to a <code>Json</code> string to throw a JsonProcessingException.</p>