title: Parsing JSON data into model objects in Java
body: <p>I haven't worked with JSON data before, thus the question. 
  I've the following JSON object in a file.</p>
  
  <pre><code>{
      "courses": [
          { "id":998", "name":"Java Data Structures", "teacherId":"375" },
          { "id":"999", "name":"Java Generics", "teacherId":"376" }
  
      ],
      "teachers": [
          { "id":"375", "firstName":"Amiyo", "lastName":"Bagchi"},
          { "id":"376", "firstName":"Dennis", "lastName":"Ritchie"}    
      ]
  }
  </code></pre>
  
  <p>Here are my model Objects.</p>
  
  <pre><code>public class Course {
  
      private int _id;
      private String _name;
      private Teacher _teacher;
  }
  
  public class Teacher {
      private int _id;
      private String _firstName;
      private String _lastName;
  }
  </code></pre>
  
  <p>My task is to read the JSON Objects and return a list of Model objects.</p>
  
  <p>I've imported the simple.JSON family of jar and here's my code that reads the file.</p>
  
  <pre><code>    FileReader reader = new FileReader(path);
      JSONParser parser = new JSONParser();
      Object obj = parser.parse(reader);
  
      JSONObject jsonObject = (JSONObject) obj;
  </code></pre>
  
  <p>My question is,</p>
  
  <ol>
  <li>How do I parse the JSON document into my Model objects?</li>
  <li>If the input file is JSON but of a different format how do I throw exception/handle the anomaly?</li>
  </ol>
  
  <p>Any help appreciated.</p>