using a Json file in Rest-assured for payload

Bhaskar Mishra picture Bhaskar Mishra · Apr 12, 2016 · Viewed 19.7k times · Source

I have a huge JSON file to be POST as payload of a rest api call for testing purposes. I tried something like :

    public void RestTest() throws Exception {
    File file = new File("/Users/bmishra/Code_Center/stash/experiments/src/main/resources/Search.json");
    String content = null;

    given().body(file).with().contentType("application/json").then().expect().
            statusCode(200).
            body(equalTo("true")).when().post("http://devsearch");


}

and get error as :

java.lang.UnsupportedOperationException: Internal error: Can't encode /Users/bmishra/Code_Center/stash/experiments/src/main/resources/Search.json to JSON.

I can run by reading the file and passing the body as string and that works but I see i can directly pass the file object and this doesnt work.

After researching enough it seems that it doesnt work. I have opened up issue with rest-assured. https://github.com/jayway/rest-assured/issues/674

Answer

Bhaskar Mishra picture Bhaskar Mishra · Apr 15, 2016

After posting the issue with rest-assured team. I have got a fix. I tested the fix and the issue is now resolved.

Message from rest-assured:

It should be fixed now so I've now deployed a new snapshot that should address this issue. Please try version 2.9.1-SNAPSHOT after having added the following Maven repository:

<repositories>
        <repository>
            <id>sonatype</id>
            <url>https://oss.sonatype.org/content/repositories/snapshots/</url>
            <snapshots />
        </repository>
</repositories>

For more information : https://github.com/jayway/rest-assured/issues/674#issuecomment-210455811