gpt4 book ai didi

java - Unirest JSONElement NoSuchMethodError

转载 作者:行者123 更新时间:2023-12-01 18:36:03 26 4
gpt4 key购买 nike

我正在使用 Unirest 库通过以下代码行调用公开可用的 REST 端点:

public void callRest() {
String url = "https://upstream.com/token"
HttpResponse<JsonNode> response = (HttpResponse<JsonNode>) Unirest.post(url).
field("username", "###").
field("password", "###").
field("grant_type", "password").
field("client_id", "####").
field("client_secret", "####").asJson().getBody();
}

我收到以下错误:

Exception in thread "main" java.lang.NoSuchMethodError: com.google.gson.Gson.newBuilder()Lcom/google/gson/GsonBuilder;
at kong.unirest.json.JSONElement.<clinit>(JSONElement.java:39)
at kong.unirest.JsonNode.<init>(JsonNode.java:44)
at kong.unirest.JsonResponse.toJsonNode(JsonResponse.java:49)
at kong.unirest.JsonResponse.getNode(JsonResponse.java:43)
at kong.unirest.JsonResponse.<init>(JsonResponse.java:35)
at kong.unirest.apache.BaseApacheClient.transformBody(BaseApacheClient.java:53)
at kong.unirest.apache.ApacheClient.request(ApacheClient.java:127)
at kong.unirest.BaseRequest.asJson(BaseRequest.java:213)

最突出的一行是

at kong.unirest.json.JSONElement.<clinit>(JSONElement.java:39)

unirest 库刚刚声明

private static transient final Gson PRETTY_GSON = new Gson().newBuilder().setPrettyPrinting().create();

在 JSONElement 类中。我遵循了 Unirest 文档中给出的确切指南,您可以在该文档中找到 here

我添加的 POM 依赖项如下:

        <dependency>
<groupId>com.konghq</groupId>
<artifactId>unirest-java</artifactId>
<version>3.3.00</version>
</dependency>
<dependency>
<groupId>com.konghq</groupId>
<artifactId>unirest-java</artifactId>
<version>3.3.00</version>
<classifier>standalone</classifier>
</dependency>

最佳答案

其实是和Unirest的版本冲突。当我删除时

        <dependency>
<groupId>com.konghq</groupId>
<artifactId>unirest-java</artifactId>
<version>3.3.00</version>
<classifier>standalone</classifier>
</dependency>

并通过 .asJson() 获取结果,然后一切都对我有用。

关于java - Unirest JSONElement NoSuchMethodError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60042060/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com