使用 Unirest API 更新 Jira Cloud

Updating Jira Cloud using the Unirest API

我可以使用 Unirest Java 库和基本身份验证访问 Jira 云。感谢 Stackflowers 让这成为可能。

我想使用相同的方式更新一张样本票的优先级。下面是 groovy 代码。它不起作用但是。你能指出我的错误在哪里吗?

     result = 
     Unirest.put("https://mysite.atlassian.net/rest/api/2/issue/TIC-1")
    .basicAuth("myuser","mypwd")
    .header('Content-Type', 'application/json')
    .body([fields: [priority: [name: 'High']]]).asString

     println result.status

显示的错误是:

enter code hereCaught: java.lang.RuntimeException: Serialization Impossible. 
Can't find an ObjectMapper implementation.
java.lang.RuntimeException: Serialization Impossible. Can't find an 
ObjectMapper implementation.
com.mashape.unirest.request.HttpRequestWithBody.body(HttpRequestWithBody.jav
a:155)
com.mashape.unirest.request.HttpRequestWithBody$body.call(Unknown Source)
JiraClient.run(JiraClient.groovy:51)

已添加所有 Maven 依赖项并且 Unirest.get() request/responses 正常工作。

以上代码有效。我们需要实现 Unirest ObjectMapper 方法。我正在使用来自以下参考的 Java 方法。它与 Groovy 脚本一起工作:

/*Ref: <http://blog.pikodat.com/2015/09/11/tooltip-unirest-lightweight-http-
request-client-libraries/>*/

Unirest.setObjectMapper(new ObjectMapper() {
private com.fasterxml.jackson.databind.ObjectMapper jacksonObjectMapper = 
new com.fasterxml.jackson.databind.ObjectMapper();

public <T> T readValue(String value, Class<T> valueType) {
    try {
        return jacksonObjectMapper.readValue(value, valueType);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

public String writeValue(Object value) {
    try {
        return jacksonObjectMapper.writeValueAsString(value);
    } catch (JsonProcessingException e) {
        throw new RuntimeException(e);
    }
}
});

并且您需要对 Jackson-bind 有额外的 Maven 依赖:

<dependency>
   <groupId>com.fasterxml.jackson.core</groupId>
   <artifactId>jackson-databind</artifactId>
   <version>2.8.8</version>
</dependency>

作为最后一步,添加缺少的导入语句:

import com.fasterxml.jackson.core.JsonProcessingException
import com.mashape.unirest.http.ObjectMapper
import com.mashape.unirest.http.Unirest

还有宾果游戏!您可以立即在外部观看 Jira 更新!享受!!