RestAssured:如何为不同类型的 Request 对象制作 POST rest assure 调用抽象

RestAssured : How to make the POST rest assure call abstract for different type of Request objects

目前这是我的 post 电话:

private static Response postRequest(String endpoint, ABC request, int expectedStatusCode) {
    return extractResponse(buildRequest().body(request).post(endpoint), expectedStatusCode);
}

现在我要添加另一个 post 端点调用,但请求对象类型不同。像这样:

 private static Response postRequest(String endpoint, XYZ request, int expectedStatusCode) {
    return extractResponse(buildRequest().body(request).post(endpoint), expectedStatusCode);
}

如何在没有冗余代码的情况下仅重载请求类型?

谢谢。

使用 java 泛型:

private static <T> Response postRequest(String endpoint, T request, int expectedStatusCode) {...}