Hipchat Message with Groovy - 找不到 ObjectMapper 实现



我在使用 Groovy 脚本时遇到问题,试图在 Unirest 的 Hipchat 中发布消息。

Caught: java.lang.RuntimeException: Serialization Impossible. Can't find an ObjectMapper implementation.
java.lang.RuntimeException: Serialization Impossible. Can't find an ObjectMapper implementation.
at com.mashape.unirest.request.HttpRequestWithBody.body(HttpRequestWithBody.java:155)
at com.mashape.unirest.request.HttpRequestWithBody$body.call(Unknown Source)
at 011.run(011.groovy:15)

这就是脚本:

@Grab(group='com.mashape.unirest', module='unirest-java', version='1.4.9')
import com.mashape.unirest.http.JsonNode
import com.mashape.unirest.http.HttpResponse
import com.mashape.unirest.http.Unirest
def apiToken = " [Token] "
Unirest.clearDefaultHeaders()
Unirest.post("https://api.hipchat.com/v2/room/ [Number] /message" )
.header("Content-Type", "application/json" )
.queryString('auth_token', apiToken)
.body(["message": "Test", "notify": True])
.asString()

提前感谢您的帮助。

您正在向.body(...)传递Map,但文档说它期望String,或JsonNode,或Object,并且对于Object,您将需要更多的配置来指定它们的序列化方式(并且Map属于该类别)。

也许你可以告诉Groovy从你的Map对象为你生成一个JSON String值:

.body(JsonOutput.toJson(["message": "Test", "notify": true]))

(JsonOutput在包装groovy.json)

最新更新