title: Using vararg to get data from nested JSON Object returns null
body: <p>I am trying to return data from a nested JSON Object in a seperate JSON file. For example, my JSON file might look like this</p>
  <pre class="lang-json prettyprint-override"><code>{
      &quot;user1&quot;: {
         
         &quot;name&quot;: &quot;John&quot;,
         &quot;age&quot;: 25,
         &quot;job&quot;: &quot;developer&quot;
  
      },
  
      &quot;day&quot;: &quot;May 2nd 2022&quot;
  }
  </code></pre>
  <p>And here is the method that I am using to pull the nested Object</p>
  <pre class="lang-java prettyprint-override"><code>    public static Object get(String key, String... objKey) throws Exception {
              
              //create new JSON parser and FileReader
              JSONParser parser = new JSONParser();
              FileReader jsonFile = new FileReader(path);
  
              //Reads the data in JSON file and assigns to Object jsonData
              Object jsonData = parser.parse(jsonFile);
  
              //assigns data to a JSONObject object
              JSONObject jsonDataObj = (JSONObject) jsonData;
  
              //checks to see if data is an array
              if(jsonDataObj.get(key).getClass().isArray()){
                  throw new Error(&quot;Data is an array and not returnable&quot;);
              }
  
              if(jsonDataObj.get(key) instanceof JSONArray){
              
                  //get JSON Object into JSONObject variable to read from
                  JSONObject jsonObj = (JSONObject) jsonDataObj.get(key);
  
                  //get wanted data from nested JSON Object
                  Object wantedData = jsonObj.get(objKey);
  
                  return wantedData;
  
              } else {
  
                  //get data associated with 'key' value in JSON Object
                  Object wantedData = jsonDataObj.get(key);
  
                  return wantedData;
  
              }
  
      } //end get()
  </code></pre>
  <p>When I call the method <code>get()</code> with only one param like <code>get(&quot;day&quot;)</code> it returns the data in day perfectly fine and nothing goes wrong. The problem is when I call the method and introduce a second argument it returns null.</p>
  <p>For example, if I call <code>get(&quot;user1&quot;, &quot;age&quot;)</code> instead of returning <code>25</code> is return <code>null</code>. I figured out that it is the vararg parameter that is messing it up since when I change the method parameters to <code>String key, String objKey</code> it works fine. Another thing that i've noticed while debuging is that if I print the vararg it prints a memory address instead of the String passed to the parameter.</p>
  <p>If it is of any help; I am using the json-simple library on Maven 1.4</p>