title: converting json into java object for a array with mixed types
body: <p>My json string looks like the following:</p>
  
  <pre><code>{
    "text": ["foo",1,"bar","2",3],
    "text1": "value1",
    "ComplexObject": {
     .....
     }
  }
  </code></pre>
  
  <p>I have a pojo defined like this:</p>
  
  <pre><code>class MyPojo {
   List&lt;String&gt; text;
   String text1;
   ComplexObject complexObject;
  }
  </code></pre>
  
  <p>I use google gson and am able to get my java object populated properly. The problem here is that the field text is an array of mixed types (string and int). So all the entries there are converted into String and i am not able to figure out which entries in the array is a string vs int. I cant use parseInt since the entries in the original array may have "2" as well as 3.</p>
  
  <p>Is there a way for me to get the right instance type of the fields in my array after converting into java object.</p>
  
  <h2>SOLUTION</h2>
  
  <p>So i implemented the solution using gson the round about way using the JsonDeserializer. And then i tried using jackson. Guess what jackson supports serializing/deserializing the mixed array type by preserving the data types.</p>
  
  <pre><code>ObjectMapper mapper = new ObjectMapper();
  MyPojo gmEntry = mapper.readValue(json, new TypeReference&lt;MyPojo &gt;(){});
  </code></pre>
  
  <p>And i can basically fetch the List&lt;Object&gt; and do an instanceof to check for the datatype.</p>
  
  <p>Shame on you gson!!    </p>