title: Using Jackson ObjectMapper with Java 8 Optional values
body: <p>I was trying to use Jackson to write a class value to JSON that has Optional as fields:</p>
  
  <pre><code>public class Test {
      Optional&lt;String&gt; field = Optional.of("hello, world!");
  
      public Optional&lt;String&gt; getField() {
          return field;
      }
  
      public static void main(String[] args) throws JsonProcessingException {
          ObjectMapper mapper = new ObjectMapper();
          System.out.println(mapper.writeValueAsString(new Test()));
      }
  }
  </code></pre>
  
  <p>When executed, this class generates the following output:</p>
  
  <pre><code>{"field":{"present":true}}
  </code></pre>
  
  <p>I understand the present/not present field being included and could work around it when reading the JSON data, however I can't get around the fact that the actual content of the optional is never written to the output. :(</p>
  
  <p>Any workarounds here except not using ObjectMapper at all?</p>