Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/397.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Unirest JSONElement NoSuchMethodError_Java_Rest_Gson_Unirest - Fatal编程技术网

Java Unirest JSONElement NoSuchMethodError

Java Unirest JSONElement NoSuchMethodError,java,rest,gson,unirest,Java,Rest,Gson,Unirest,我使用Unirest库调用公共可用的REST端点,代码行如下: public void callRest() { String url = "https://upstream.com/token" HttpResponse<JsonNode> response = (HttpResponse<JsonNode>) Unirest.post(url). field("username", "###"). fie

我使用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();
}
在JSONElement类中。我遵循了您可以找到的Unirest文档中给出的确切指南

我添加的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>

com.konghq
unirest java
3.3.00
com.konghq
unirest java
3.3.00
独立的

实际上,这是与Unirest的版本冲突。当我删除

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

com.konghq
unirest java
3.3.00
独立的
通过
.asJson()
获取结果,然后一切都对我有利

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

        <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>
        <dependency>
            <groupId>com.konghq</groupId>
            <artifactId>unirest-java</artifactId>
            <version>3.3.00</version>
            <classifier>standalone</classifier>
        </dependency>