Using a Json file in Rest-assured for payload

2,238 views
Skip to first unread message

Bhaskar Mishra

unread,
Apr 14, 2016, 7:39:56 AM4/14/16
to REST assured

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.
json

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.

Johan Haleby

unread,
Apr 14, 2016, 7:53:06 AM4/14/16
to rest-a...@googlegroups.com
Hi, 

Hmmm "body" assumes binary content-type but I'm not sure if this is actually correct (as in your case). Could you please open a new issue and I'll investigate it further? Note that if your file is as huge as you say you probably want to use multipart uploading instead and you can specify JSON and content-type for multiparts in RA.

/Johan

--
You received this message because you are subscribed to the Google Groups "REST assured" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rest-assured...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Bhaskar Mishra

unread,
Apr 14, 2016, 2:08:36 PM4/14/16
to REST assured
My file is not that very huge. And I am looking for a cleaner implementation so that my Integration testers don't have to think much. For now I have a common class which can convert file content to string and it works fine. I have opened uo the issue :
https://github.com/jayway/rest-assured/issues/674

Johan Haleby

unread,
Apr 14, 2016, 2:32:45 PM4/14/16
to rest-a...@googlegroups.com
Thanks
--
You received this message because you are subscribed to the Google Groups "REST assured" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rest-assured...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Sent from my phone
Reply all
Reply to author
Forward
0 new messages