title: Deserialize to String or Object using Jackson
body: <p>I have an object that sometimes looks like this:</p>
  
  <pre><code>{
     "foo" : "bar",
     "fuzz" : "bla"
  }
  </code></pre>
  
  <p>and sometimes looks like this:</p>
  
  <pre><code>{
     "foo" : { "value" : "bar", "baz": "asdf" },
     "fuzz" : { "thing" : "bla", "blip" : "asdf" }
  }
  </code></pre>
  
  <p>these classes would look like:</p>
  
  <pre><code>public class Foo {
     String value;
     String baz;
  }
  
  public class Fuzz {
     String thing;
     String blip;
  }
  
  </code></pre>
  
  <p>where the first cases are shorthand for the second ones.  I would like to always deserialize into the second case.</p>
  
  <p>Further - this is a pretty common pattern in our code, so I would like to be able to do the serialization in a generic manner, as there are other classes similar to <code>Foo</code> above that have the same pattern of using String as a syntactic sugar for a more complex object.</p>
  
  <p>I'd imagine the code to use it would look something like this</p>
  
  <pre><code>
  public class Thing { 
    @JsonProperty("fuzz")
    Fuzz fuzz;
  
    @JsonProperty("foo")
    Foo foo;
  }
  
  </code></pre>
  
  <p>How do I write a custom deserializer (or some other module) that generically handles both cases?</p>