我的测试中的应用程序定义了如下端点:
@ResponseBody
@RequestMapping(value = "maxsize", method = RequestMethod.POST)
public ResponseEntity<Void> changeMaxQuoteSize(@RequestBody DataRequest dataRequest,
@AuthenticationPrincipal UserProfile userProfile) {
orderManager.scheduleUpdateCurrencyConfigRules(dataRequest.getCurrency(),
(c) -> c.setMaxQuoteSize(dataRequest.getMaxSize()))
return ResponseEntity.status(HttpStatus.OK).build();
}
我想使用"放心"向它发送消息,但我的问题是如何将请求主体映射到DataRequest对象?
我试过了:
class DateRq {
private String curpair;
private Double maxQuoteSize;
public DateRq(String curpair, Double maxQuoteSize) {
this.curpair = curpair;
this.maxQuoteSize = maxQuoteSize;
}
}
@Test
public void test() {
String endpoint = "http://127.0.0.1:8095/api/maxsize";
DateRq request = new DateRq(TICKER_SYMBOL, 5_000_000D);
Response response = RestAssured.given()
.when()
.body(request)
.post(endpoint);
assertEquals(200, response.getStatusCode());
}
但是接收到这样的错误:com.fasterxml.jackson.databind.exc.InvalidDefinitionException:找不到类com的序列化程序…PMTest$DateRq,也找不到创建BeanSerializer的属性(为避免异常,请禁用SerializationFeature.FAIL_ON_EMPTY_BEANS(
我尝试了某种JSON,但没有收到任何响应:
@Test
public void test() {
String endpoint = "http://127.0.0.1:8095/api/maxsize";
String request = new JSONObject()
.put("curpair", TICKER_SYMBOL)
.put("maxQuoteSize", 5_000_000D)
.toString();
Response response = RestAssured.given()
.when()
.body(request)
.post(endpoint);
assertEquals(200, response.getStatusCode());
}
你试过这样的代码吗?
DateRq request = new DateRq(TICKER_SYMBOL, 5_000_000D);
Response response = RestAssured.given()
.body(request)
.when()
.post(endpoint);