title: Jackson deserialization ... Unexpected token (END_OBJECT),
body: <p>I am trying to deserialize a JSON array into a Java Collection using Jackson. This motivated by the answers to this question I asked last night <a href="https://stackoverflow.com/questions/6424848/can-i-instantiate-a-superclass-and-have-a-particular-subclass-be-instantiated-bas">Can I instantiate a superclass and have a particular subclass be instantiated based on the parameters supplied</a>.</p>
  
  <p>The error I am gettings is (line breaks added for readability):</p>
  
  <pre><code>org.codehaus.jackson.map.JsonMappingException: 
      Unexpected token (END_OBJECT), expected FIELD_NAME: missing property 'type'
      that is to contain type id  (for class sempedia.model.query.QueryValue)
   at [Source: java.io.StringReader@325aef; line: 1, column: 175] 
      (through reference chain: sempedia.model.query.QueryProperty["values"])
  </code></pre>
  
  <p>My situation is quite complicated. My array contains objects which themselves contain a value which is an array. This array in turn contains values which are also objects but are not necessarily the same (thus polymorphism).</p>
  
  <p>Here is a sample JSON string:</p>
  
  <pre><code>[
      {
        "id":"74562",
        "uri":"http://dbpedia.org/ontology/family",
        "name":"family",
        "values":[
           {
              "id":"74563",
              "uri":"http://dbpedia.org/resource/Orycteropodidae",
              "name":"Orycteropodidae"
           }
        ],
        "selected":false
      },
      {
        "id":"78564",
        "uri":"http://dbpedia.org/ontology/someNumber",
        "name":"someNumber",
        "values":[
           {
              "lower":"45",
              "upper":"975",
           }
        ],
        "selected":true
      }
  ]
  </code></pre>
  
  <p>I would like to use this (below) code or something similar to get an object which is an instance of <code>Collection&lt;QueryProperty&gt;</code> which I have called <code>queryProperties</code></p>
  
  <pre><code>ObjectMapper mapper = new ObjectMapper();  
  Collection&lt;QueryProperty&gt; queryProperties = 
     queryProperties = mapper.readValue(query, 
        new TypeReference&lt;Collection&lt;QueryProperty&gt;&gt;(){});
  </code></pre>
  
  <p>My classes for deserialization (they have public getters/setters which I am not printing) are listed below:</p>
  
  <pre><code>public class QueryProperty {    
      int id;
      String uri;
      String name;
      Set&lt;QueryValue&gt; values;
      String selected;
  }
  
  @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type")  
  @JsonSubTypes({  
      @Type(value = ResourceQueryValue.class),  
      @Type(value = NumericQueryValue.class)
      })  
  public abstract class QueryValue {
      String type;
  }
  </code></pre>
  
  <p><code>ResourceQueryValue</code></p>
  
  <pre><code>public class ResourceQueryValue extends QueryValue{
      int id;
      String uri;
      String name;
  }
  </code></pre>
  
  <p><code>NumericQueryValue</code> the same JSON doesn't include an object of this type.</p>
  
  <pre><code>public class NumericQueryValue extends QueryValue{
      double lower;
      double upper;
  }
  </code></pre>
  
  <p>Initial part of Stack trace:</p>
  
  <pre><code>org.codehaus.jackson.map.JsonMappingException: Unexpected token (END_OBJECT), expected FIELD_NAME: missing property 'type' that is to contain type id  (for class sempedia.model.query.QueryValue)
   at [Source: java.io.StringReader@325aef; line: 1, column: 175] (through reference chain: sempedia.model.query.QueryProperty["values"])
      at org.codehaus.jackson.map.JsonMappingException.from(JsonMappingException.java:163)
      at org.codehaus.jackson.map.deser.StdDeserializationContext.wrongTokenException(StdDeserializationContext.java:240)
      at org.codehaus.jackson.map.jsontype.impl.AsPropertyTypeDeserializer.deserializeTypedFromObject(AsPropertyTypeDeserializer.java:86)
      at org.codehaus.jackson.map.deser.AbstractDeserializer.deserializeWithType(AbstractDeserializer.java:89)
  </code></pre>