【问题标题】:Hipchat Message with Groovy - Can't find an ObjectMapper implementation带有 Groovy 的 Hipchat 消息 - 找不到 ObjectMapper 实现
【发布时间】:2017-09-26 13:05:58
【问题描述】:

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

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()

提前感谢您的帮助。

【问题讨论】:

    标签: json groovy unirest hipchat


    【解决方案1】:

    您将Map 传递给.body(...),但文档说它需要StringJsonNodeObject,对于Objects,您需要更多配置指定它们的序列化方式(Map 属于该类别)。

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

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

    JsonOutput 在包中groovy.json

    【讨论】:

      猜你喜欢
      • 2015-08-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-07
      • 1970-01-01
      • 2012-04-22
      • 2015-03-12
      • 1970-01-01
      相关资源
      最近更新 更多