I am facing - java.lang.ClassCastException: org.json.simple.JSONObject cannot be cast to org.json.JSONObject error while casting org.json.simple.JSONObject to org.json.JSONObject, I am not using JSONArray as it is suggested in one of the question asked earlier. below is my code, I am trying to assert JSONObject from API to JSONObject from a json text file. The exception is coming on "jsonObject = (JSONObject) obj;"
line number 42.
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import org.json.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import com.xxxxxx.glue.resin.Resin;
import com.xxxxxx.glue.resin.ResinDataFactory;
import com.xxxxxx.glue.resin.ResinResponse;
class OLUtil {
public static JSONObject getJsonForOLResponse(String uri){
JSONObject jsonObj = null;
try {
Resin resinAPI = ResinDataFactory.getResinAPI(null, null, null, null, null, null, uri, null);
ResinResponse apiResponse = resinAPI.resinGet();
jsonObj = apiResponse.getJsonResponse();
} catch(Exception e ){
e.printStackTrace();
}
return jsonObj;
}
public static JSONObject getJsonForOLTestData(File expectedDataJsonDataPath){
FileReader reader = null;
JSONObject jsonObject = null;
try {
reader = new FileReader(expectedDataJsonDataPath);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
JSONParser jsonParser = new JSONParser();
try {
Object obj = jsonParser.parse(reader);
jsonObject = (JSONObject) obj;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return jsonObject;
}
}