title: Reading multiple JSON Objects from a single file into Java with Jackson
body: <p>So I've done my best to research similar issues like this, but I'm fairly new to Java and JSON, so I apologize if this is redundant.  I'm working on a simple text based RPG for my Java class this semester, and I want to store character information and location information in either XML or JSON.  I've given both a try, and seem to be getting farther with JSON and Jackson.  I've written some tester code to try this out before implementing in my game, but basically I want each game "location" to have an integer ID#, some string information, and a list of exitNodes (which will eventually correspond to other locations in the game).  Here is an example of my JSON:</p>
  
  <pre><code>{
  "1":{
      "enterInfo":"Test Location Information",
      "exitNodes":[2,3]
  },
  "2":{
      "enterInfo":"More Test Location Info",
      "exitNodes":[4,5]
  },
  "3":{
      "enterInfo":"More Test Location Info",
      "exitNodes":[6,7]
  }
  }
  </code></pre>
  
  <p>I'm guessing I could organize my JSON a bit better, but ideally I want to be able to grab an object by it's number, and get the "enterInfo" and "exitNodes" back.  I've spent hours trying different things without success, but the best I can do is grab the whole JSON document as a JsonNode which just gives me the entire structure, but not an individual object.</p>
  
  <p>Here is a test class (minus constructor/getters/setters/methods) I'm trying to get the JSON into:</p>
  
  <pre><code>public class ObjectTest{
      int id;
      String enterInfo;
      int[] exitNodes;
  }
  </code></pre>
  
  <p>And here is what I have working so far, I realize that I'm not even close to achieving my goal here, but I'm out of ideas and the documentation is starting to get confusing, so I've removed my attempts to isolate one of the objects in the JSON file and instantiate an "ObjectTest" object:</p>
  
  <pre><code>package jacksontester;
  
  
  import com.fasterxml.jackson.databind.JsonNode;
  import com.fasterxml.jackson.databind.ObjectMapper;
  import java.io.File;
  import java.io.IOException;
  
  
      public class JackSONTester {
  
      public static void main(String[] args) throws IOException {
          ObjectMapper mapper = new ObjectMapper();
          JsonNode localeTemp = mapper.readTree(new File("src/jacksontester/TestMeJSON.json"));
          System.out.println(localeTemp);
      }
  }
  </code></pre>
  
  <p>Not that it really matters, but here is what prints out:</p>
  
  <pre><code>{"1":{"enterInfo":"Test Location Information","exitNodes":[2,3]},"2":{"enterInfo":"More Test Location Info","exitNodes":[4,5]},"3":{"enterInfo":"More Test Location Info","exitNodes":[6,7]}}
  </code></pre>
  
  <p>What I want to achieve is being able to create an "ObjectTest" object with the values from my JSON.  Again, sorry if this is a duplicate, I've read through numerous posts already, but I'm new here...</p>
  
  <p>EDIT:  I'm realizing now that my JSON file should probably be organized more like this:</p>
  
  <pre><code>{"locations":[
       {   "id":0,
           "enterInfo":"Test Location Information",
           "exitNodes":[1,2]
       },
       {   "id":1,
           "enterInfo":"More Test Location Info",
           "exitNodes":[2,3]
       },
       {   "id":2,
           "enterInfo":"More Test Location Info",
           "exitNodes":[4,5]
       }
       ]
       }
  </code></pre>
  
  <p>I would need to then create a list of objects defined by the JSON?</p>