我在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()提前谢谢你的帮助。
发布于 2017-04-29 15:37:58
您正在将一个Map传递给.body(...),但是文档表示它需要一个String、一个JsonNode或一个Object,对于Object,您需要更多的配置来指定它们是如何序列化的(而Map就属于这个类别)。
也许您可以告诉Groovy从Map对象中为您生成一个JSON字符串值:
.body(JsonOutput.toJson(["message": "Test", "notify": true]))(JsonOutput在groovy.json包中)
https://stackoverflow.com/questions/43679755
复制相似问题