【发布时间】:2018-10-12 09:25:59
【问题描述】:
我写了一个Restfull webservice POST api 调用,这个api 接受java object 作为请求参数
示例代码:
@POST
@Path("/sample")
@ApiOperation(value = "insert sample data",
notes = "insert sample data", response = SampleRequest.class)
public Response processSampleData(@ApiParam(value = "SampleRequest", required = true) SampleRequest sampleRequest) {
//code to insert data
}
我正在编写一个集成测试方法,但无法将java object 传递给RestClient
样品测试方法:
def "process sample data"(){
when:
/*String json = '{"sampleDataList":[{ "name": "test1", "id": "12345" },{ "name": "test2", "id": "123456"}]}'*/
Sample sample= new Sample();
sample.setName("test1");
sample.setId("12345");
SampleRequest reqObj = new SampleRequest();
reqObj.getSampleList().add(sample);
//tried with json
/*HttpResponseDecorator response = getRestClient().post([path: "$BASE_URL"+"/sample", body: json])*/
//tried with java object also
HttpResponseDecorator response = getRestClient().post([path: "$BASE_URL"+"/sample", body: SampleRequest])
then:
response
}
我尝试同时使用json 和java object,但它们都不适合我。获取No encoder found for request content type */* 错误
【问题讨论】:
标签: java spock rest-client