title: Help for Mapping JSON Twitter answer to Jaxb with Jettison
body: <p>I'm a bit new to use JSON format manipulation and not very experimented in JAXB either.
  What I try to do is building a small client to launch search on Twitter. My starting framework is JBoss RESTEasy (JAX-RS implementation) that provides an elegant way to consume Rest services JSON services by mapping JSON to JAXB thru Jettison framework (it works also in the other way if you want to provide REST service and produce JSON from JAXB).</p>
  
  <p>So I launch a simple request to Twitter :</p>
  
  <pre><code>http://search.twitter.com/search.json?q=java
  </code></pre>
  
  <p>And the answer comes in the following JSON format</p>
  
  <pre><code>{
  "results":
  [
    {"from_user_id_str":"67875385",
    "profile_image_url":"http://a2.twimg.com/axt_normal.png",
    "created_at":"Sun, 28 Nov 2010 22:38:39 +0000",
    "from_user":"extant",
    "id_str":"9013327095136256",
    "metadata":{"result_type":"recent"},
    "to_user_id":null,
    "text": "New blog post: No fancy swap in java",
    "id":9013327095136256,
    "from_user_id":67875385,
    "geo":null,
    "iso_language_code":"en",
    "to_user_id_str":null,
    "source":"wordpress"
    }, 
    &lt;more tweets...&gt;
  ],
  "max_id":9013327095136256,
  "since_id":0,
  "refresh_url":"?since_id=9013327095136256&amp;q=java",
  "next_page":"?page=2&amp;max_id=9013327095136256&amp;q=java",
  "results_per_page":15,
  "page":1,"completed_in":0.020154,
  "since_id_str":"0",
  "max_id_str":"9013327095136256",
  "query":"java"
  } 
  </code></pre>
  
  <p>So I created two classes to map this answer</p>
  
  <pre><code>@BadgerFish
  @XmlRootElement
  @XmlAccessorType(XmlAccessType.FIELD)
  public class SearchResults { 
   @XmlElement
   public List&lt;Tweet&gt; results;
   @XmlElement(name = "max_id")
   public long maxId;
   @XmlElement(name = "since_id")
   public long sinceId;
  }
  </code></pre>
  
  <p>and </p>
  
  <pre><code>@BadgerFish
  @XmlRootElement(name="tweet")
  public class Tweet {
  
   @XmlElement(name = "id")
   public long id;
  
   @XmlElement(name = "text")
   public String text;
  
   @XmlElement(name = "created_at")
   public Date createdAt;
  
   @XmlElement(name = "from_user")
   public String fromUser;
  
   @XmlElement(name = "profile_image_url")
   public String profileImageUrl;
  
   @XmlElement(name = "to_user_id")
   public Long toUserId;
  
   @XmlElement(name = "from_user_id")
   public long fromUserId;
  
   @XmlElement(name = "language_code")
   public String languageCode;
  
   @XmlElement(name = "source")
   public String source;
  
  }
  </code></pre>
  
  <p>My Twitter RESTEasy client is a simple interface</p>
  
  <pre><code>public interface TwitterResource {
   @Path("/search.json")
   @Consumes("application/*+json")
   @GET
   SearchResults search(@QueryParam("q")String query); 
  }
  </code></pre>
  
  <p>Which is exploited with the following RESTEasy code :</p>
  
  <pre><code>...
  TwitterResource tr = ProxyFactory.create(TwitterResource.class, "http://search.twitter.com");
  SearchResults sr = tr.search("java");
  ...
  </code></pre>
  
  <p>This code give the following Exception :</p>
  
  <pre><code>Exception in thread "main" org.jboss.resteasy.plugins.providers.jaxb.JAXBUnmarshalException: javax.xml.bind.JAXBException
   - with linked exception:
  [org.codehaus.jettison.json.JSONException: JSONObject["results"] is not a JSONObject.]
   at org.jboss.resteasy.plugins.providers.jaxb.AbstractJAXBProvider.readFrom(AbstractJAXBProvider.java:86)
  </code></pre>
  
  <p>I assume it comes from a wrong JAXB mapping on SearchResults class but can't figure how to correct it (and it's complicated with the JSON translation to XML). Any clue to correct it would be great.</p>
  
  <p>Thanks in advance</p>