title: How to find the type of JSON object in java dynamically?
body: <blockquote>
    <p>{'sampleJSON': {'name':'john', 'city':'delhi', 'contact' :
    ['abc.xyz@gmail.com', 9999999999 , {'city' : 'delhi','state' :
    'delhi'}] } }</p>
  </blockquote>
  
  <p>I have written a webservice in java which processes the above json object. </p>
  
  <p>Here i have contact field which can be an array of contact details. 
  To process it, what i did is</p>
  
  <pre><code>Object[] contact = getContact();
  
  for(Object c : contact)
      { 
  
      if(c instanceof String)
      {
      //do some processing
      }
  
  
      else if(c instanceof Address)
      {
      //do some processing
      }
  
      else
      {
      //throw exception..invalid format for a contact detail.
      }
  }
  </code></pre>
  
  <p>where Address is user defined class which contains the fields City and State.</p>
  
  <p>Now my code is throwing exception even though I am sending data in correct way.</p>
  
  <p>Is my approach is wrong ? </p>