title: Parsing JSON file with Jackson for Android (Java)
body: <p>Title says all. Trying to simply parse a JSON file I added to this android project via Jackson to use throughout my app.</p>
  
  <p>I was able to to do this successfully in a regular Java Application, but not in an Android project for an unknown reason. Will post both codes.</p>
  
  <p>Android Code:</p>
  
  <pre><code>public class MainActivity extends ActionBarActivity {
  
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          ObjectMapper mapper = new ObjectMapper();
          InputStream is = MainActivity.class.getResourceAsStream("contacts.json");
  
          mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
  
          List&lt;Contact&gt; contacts = null;
          Contact contact = null;
  
          try {           
              // THIS IS THE LINE THAT BREAKS
              contacts = mapper.readValue(is, TypeFactory.defaultInstance().constructCollectionType(List.class, Contact.class));
              contact = contacts.get(0);
          } catch (JsonParseException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          } catch (JsonMappingException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          } catch (IOException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }     
      }
  }
  </code></pre>
  
  <p>Again, here's the line that breaks:</p>
  
  <pre><code>contacts = mapper.readValue(is, TypeFactory.defaultInstance().constructCollectionType(List.class, Contact.class));
  </code></pre>
  
  <p>This is the LogCat of the error:</p>
  
  <pre><code>com.fasterxml.jackson.databind.JsonMappingException: No content to map due to end-of-input
  </code></pre>
  
  <p>I've searched this plenty and have not found a solution for this trivial task. I'd like to also know why this code works in a Java Application but not in an Android Project. If onCreate could throw those exceptions like Main can in the Java App I think it would work, but obviously it can't.  Thanks for the solution in advance.</p>
  
  <hr>
  
  <p>Just for reference, here is my working Java Application code of using Jackson to parse a JSON file.</p>
  
  <pre><code>package test;
  
  // file with accessors and mutators for JSON
  import test.Contact;
  
  import java.io.IOException;
  
  import com.fasterxml.jackson.databind.DeserializationFeature;
  import com.fasterxml.jackson.databind.JsonMappingException;
  import com.fasterxml.jackson.databind.ObjectMapper;
  import com.fasterxml.jackson.databind.type.TypeFactory;
  import com.fasterxml.jackson.core.JsonParseException;
  
  import java.io.InputStream;
  import java.util.List;
  
  public class test {
  
      public static void main(String[] args) throws JsonParseException, JsonMappingException, IOException {
  
          ObjectMapper mapper = new ObjectMapper();
          InputStream is = test.class.getResourceAsStream("contacts.json");
          mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
  
          List&lt;Contact&gt; contacts = mapper.readValue(is, TypeFactory.defaultInstance().constructCollectionType(List.class, Contact.class));
  
          // point to first contact
          Contact contact = contacts.get(0);
  
          for (int i = 0; i &lt; contacts.size(); i++) {
              contact = contacts.get(i);
              System.out.println(contact.getName());
              System.out.println(contact.getEmployeeId());
              System.out.println(contact.getCompany());
              System.out.println(contact.getDetailsURL());
              System.out.println(contact.getSmallImageURL());
              System.out.println(contact.getBirthdate());
              System.out.println(contact.getPhone().getWork());
              System.out.println(contact.getPhone().getHome());
              System.out.println(contact.getPhone().getMobile());
          }
      }
  
  }
  </code></pre>