title: Jackson java.util.Optional serialization does not include type ID
body: <p>I got the following classes:</p>
  
  <pre><code>@JsonIdentityInfo(
      generator = ObjectIdGenerators.IntSequenceGenerator.class,
      property = "oid"
  )
  @JsonTypeInfo(
      use = JsonTypeInfo.Id.NAME,
      include = JsonTypeInfo.As.PROPERTY,
      property = "clazz")
  @JsonSubTypes({
      @JsonSubTypes.Type(value = MySubEntity.class, name = "MySubEntity"),
  })
  public abstract class Entity {
      ...
  }
  
  public class MySubEntity extends Entity {
      ...
  }
  </code></pre>
  
  <p>Now when I serialize that <code>MySubEntity</code> wrapped in an <code>Optional</code> then JSON does not contain the <code>clazz</code> attribute containing the type ID. <strong>Bug?</strong> When I serialize to <code>List&lt;MySubEntity&gt;</code> or just to <code>MySubEntity</code> it works fine.</p>
  
  <p>Setup: jackson-databind 2.9.4, jackson-datatype-jdk8 2.9.4, serialization is done in Spring Boot application providing a RESTful web service.</p>
  
  <p><strong>EDIT:</strong> Here is the Spring REST method that returns the <code>Optional</code>:</p>
  
  <pre><code>@RequestMapping(method = RequestMethod.GET, value = "/{uuid}", produces = "application/json")
  public Optional&lt;MySubEntity&gt; findByUuid(@PathVariable("uuid") String uuid) {
      ...
  }
  </code></pre>
  
  <p><strong>EDIT:</strong>
  I <a href="https://www.dropbox.com/s/719poeehq6z05ac/demo-49071166.zip?dl=0" rel="nofollow noreferrer">made a SSCCE</a> with a simple Spring REST controller and two tests. The first test is using <code>ObjectMapper</code> directly which is successful in deserialization although the <code>clazz</code> is missing. The second test calls the REST controller and fails with an error because <code>clazz</code> is missing:</p>
  
  <blockquote>
    <p>Error while extracting response for type [class com.example.demo.MySubEntity] and content type [application/json;charset=UTF-8]; nested exception is org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Missing type id when trying to resolve subtype of [simple type, class com.example.demo.MySubEntity]: missing type id property 'clazz'; nested exception is com.fasterxml.jackson.databind.exc.InvalidTypeIdException: Missing type id when trying to resolve subtype of [simple type, class com.example.demo.MySubEntity]: missing type id property 'clazz'</p>
  </blockquote>