我需要在REST Assured中配置底层的Jackson ObjectMapper.我正在使用REST Assured编写REST API测试,我需要定义一些过滤器来注册ObjectMapper,用于将我的对象序列化为JSON:
String newTestSuite = "{\"name\":\"Added through Rest API\",\"description\":\"Test Description\",\"steps\":[]}";
FilterProvider filters = new SimpleFilterProvider().addFilter("createNewTestSuite", new NewTestSuiteFilter());
ObjectMapper om = new ObjectMapper();
om.setFilters(filters);
try {
TestSuite ts = om.readValue(newCaspianTest, TestSuite.class);
RequestSpecification requestSpec = new RequestSpecBuilder()
.setBaseUri("https://somesite.com")
.setBody(ts)
.setUrlEncodingEnabled(false)
.build();
ResponseSpecification responseSpec = new ResponseSpecBuilder()
.expectStatusCode(200)
.expectStatusLine(Matchers.containsString("200 OK"))
.build();
RestAssured.given()
.auth().basic("testUser","testPassword")
.spec(requestSpec)
.log().all()
.post("/restendpoint")
.then()
.log().all()
.spec(responseSpec);
} catch(JsonParseException jpe) {
} catch(JsonMappingException jme) {
} catch(IOException ioe) {
}
}
Run Code Online (Sandbox Code Playgroud)
}