Join 34,000+ subscribers and receive articles from our
blog about software quality, testing, QA and security.

Org.json.simple.JSONObject cannot be cast to org.json.JSONObject


#1

Hello,

I’ve got the following code within a JUnit test in IntelliJ:

 @Test
    public void checkWebpage_01Title() throws InterruptedException, IOException, APIException {

        Thread.sleep(10000);

        assertTrue("Error with page title on Main Page.", driver.getTitle().equals("Hello"));

        Map data = new HashMap();
        data.put("status_id", new Integer(1));
        data.put("comment", "This test worked fine!");
        JSONObject r = (JSONObject) client.sendPost("add_result_for_case/9/217", data);

    }

However, I am getting the following error when I run the test:

java.lang.ClassCastException: org.json.simple.JSONObject cannot be cast to org.json.JSONObject

This is on the last line.

Any ideas why this is occuring?

Many thanks

Mark


#2

Hello,

Ignore this post, it’s my mistake. I’d imported org,json.JSONObject; instead of import org.json.simple.JSONObject;

Regards

Mark


#3

Hi Mark,

Yep, it’s org.json.simple and you can also find some sendGet/sendPost examples on our website in case you haven’t seen them already:

http://docs.gurock.com/testrail-api2/bindings-java

Cheers,
Tobias