title: How to trigger calls to .serializeWithType() of a class implementing JsonSerializable in Jackson?
body: <p>This is Jackson 2.2.x.</p>
  
  <p>I have a class implementing <a href="http://fasterxml.github.io/jackson-databind/javadoc/2.2.0/com/fasterxml/jackson/databind/JsonSerializable.html" rel="noreferrer"><code>JsonSerializable</code></a>; there are two methods to implement for this interface, <code>serialize()</code> and <code>serializeWithType()</code>.</p>
  
  <p>I want to test {de,}serialization of this class, and I can trigger calls to <code>serialize()</code> easily; not, however, <code>serializeWithType()</code>.</p>
  
  <p>The <a href="http://fasterxml.github.io/jackson-databind/javadoc/2.2.0/com/fasterxml/jackson/databind/JsonSerializable.html#serializeWithType(com.fasterxml.jackson.core.JsonGenerator,%20com.fasterxml.jackson.databind.SerializerProvider,%20com.fasterxml.jackson.databind.jsontype.TypeSerializer)" rel="noreferrer">javadoc for this latter method</a> says that this method is called</p>
  
  <blockquote>
    <p><em>[...]</em> when additional type information is expected to be included in serialization, for deserialization to use.</p>
  </blockquote>
  
  <p>I just don't understand what this means...</p>
  
  <p>How do I set up a test environment so that this method be called? Note that the JSON to be serialized can be of any type except object (ie, boolean, number, string, array are all valid types).</p>