When transferring keys of type Iterator , an output problem occurs in the valueChecker() method. I wrote in the comments to the code what is wrong with my result. What am I doing wrong ?
public Map<Class, Object> JSONFormatStringSeparator(JSONObject jsonObject) { Iterator<String> keys = jsonObject.keys(); while (keys.hasNext()){ String key = keys.next(); System.out.println(key); // выводит все ключи } String value = valueChecker(keys,jsonObject); // вызываю метод и передаю ключи и сам Json object System.out.println("After value checker!"); // выводит if(value!=null) { switch (value) { case "create-company": String [] array = {"id","compname","password","email"}; if(keyChecker(keys,array) == array.length){ System.out.println("All found"); Company company = new Company(jsonObject.getLong("id"),jsonObject.getString("compname"), jsonObject.getString("password"),jsonObject.getString("email")); return objectMapper(Company.class,company); } } } return null; } private String valueChecker(Iterator<String> keys,JSONObject jsonObject){ System.out.println("in the value checker!"); // выводит while(keys.hasNext()){ // не заходит и метод возврашает null! String key = keys.next(); System.out.println("in value checker loop!"); if(key.equals("formId")){ return (String)jsonObject.get(key); } } return null; }