title: Jackson JSON Deserialization of MongoDB ObjectId
body: <p>Ok, so first off here's the JSON that's returning from my web service. I'm trying to deserialize it into pojos after an asynchronous query in a ResponseHandler in my Android ContentProvider.</p>
  
  <pre><code>{"exampleList" : [{
  "locationId" : "00001" , 
  "owners" : [ 
    { 
      "paidID" : { "$oid" : "50a9c951300493f64fbffdb6"} , 
      "userID" : { "$oid" : "50a9c951300493f64fbffdb6"}
    } , 
    { 
      "paidID" : { "$oid" : "50a9c951300493f64fbffdb7"} , 
      "userID" : { "$oid" : "50a9c951300493f64fbffdb7"}
    } 
  ]
  }]}
  </code></pre>
  
  <p>At first, I was confused about the problem I was seeing, since I use the same Jackson-annotated beans for my web service as I do in my Android app--but then I realized that the <code>owners</code> object was never getting sent in the sample JSON to my web service (it skips the POJOs on my web service and gets added into the documents in mongoDB through atomic updates from the DAO).</p>
  
  <p>So OK. Up to now, Jackson wasn't having to handle the <code>owners</code> object, and now that it is it is choking on it, namely:</p>
  
  <blockquote>
    <p><code>JsonMappingException</code>: Can not deserialize instance of <code>java.lang.String</code> out of 
    <code>START_OBJECT</code> token at [char position where you can find <code>"userID"</code> and <code>"paidID"</code>] 
    through reference chain [path to my Jackson bean which contains the owners class]</p>
  </blockquote>
  
  <p>My Jackson bean has a wrapper, which is what that "exampleList" is all about:</p>
  
  <pre><code>public class Examples extends HashMap&lt;String, ArrayList&lt;Example&gt;&gt; {
  
  }
  </code></pre>
  
  <p>And then the actual <code>Example</code> class:</p>
  
  <pre><code>@JsonIgnoreProperties(ignoreUnknown = true)
  public class Example implements Comparable&lt;Example&gt; {
  
  @ObjectId @Id
  private String id;
  
  @JsonProperty(Constants.Example.location)
  private String location;
  
  @JsonProperty(Constants.Example.OWNERS)
  private List&lt;Owners&gt; owners;
  
  public int compareTo(Example _o) {
      return getId().compareTo(_o.getId());
  }
  
  public String getId() {
      return id;
  }
  
  public void setId(String id) {
      this.id = id;
  }
  
  public String getLocation() {
      return location;
  }
  
  public void setLocation(String location) {
      this.location = location;
  }
  public List&lt;Example.Owners&gt; getOwners() {
      return owners;
  }
  
  public void setOwners(List&lt;Example.Owners&gt; owners) {
      this.owners = owners;
  }
  
  public Example() {
  }
  
  @JsonCreator
  public Example(@Id @ObjectId String id) {
      this.id = id;
  }
  
  @JsonIgnoreProperties(ignoreUnknown = true)
  public static class Owners implements Comparable&lt;Owners&gt; {
  
      @JsonProperty(Constants.Example.USERID)
      private String userID;
  
      @JsonProperty(Constants.Example.PAIDID)
      private String paidID;
  
      public Owners() {
      }
  
      public int compareTo(Owners _o) {
          return getUserID().compareTo(_o.getUserID());
      }
  
      @ObjectId
      public String getUserID() {
          return userID;
      }
  
      @ObjectId
      public void setUserID(String userID) {
          this.userID = userID;
      }
  
      @ObjectId
      public String getPaidID() {
          return paidID;
      }
  
      @ObjectId
      public void setPaidID(String paidID) {
          this.paidID = paidID;
      }
  
  }
  
  }
  </code></pre>
  
  <p>And finally, the code in the ResponseHandler where this is all failing (the 2nd line produces the JsonMappingException):</p>
  
  <pre><code>objectMapper = MongoJacksonMapperModule.configure(objectMapper);    
  mExamples = objectMapper.readValue(jsonParser, Examples.class);
  </code></pre>
  
  <p>I have a feeling the issue is that Jackson still doesn't know how to map those <code>$oid</code>, which are the mongoDB ObjectIds. The MongoJacksonMapper library is supposed to help that by providing the <code>@ObjectId</code> annotation and a way to configure the ObjectMapper to use that library, but it still isn't working. For some reason, it's still looking for the userID or paidID as a String, not an ObjectId. Any ideas?</p>