【问题标题】:How to convert a Gatling jsonFeeder with nested structures to json request body?如何将具有嵌套结构的 Gatling jsonFeeder 转换为 json 请求正文?
【发布时间】:2021-12-19 10:06:03
【问题描述】:

我有一个 json feeder 从一个文件中读取一个这样的 json 数组:

[{ "a": {"b": 1} }, { "a": {"b": 2} }]

当我将它用于请求正文时,它会像ArraySeq(HashMap(.. 一样发送,而不是实际的 json。如何将 Parsed Json 转换回 Json 保持馈线方法?

val jsonFileFeeder = jsonFile("requests.json").circular

val scn = scenario("cost estimation")
  .feed(jsonFileFeeder)
  .exec(
    http("request_1")
      .post("/")
      .body(StringBody(
        """{
    "a":  "${a}"
}"""
      )).asJson
  )

【问题讨论】:

    标签: json scala gatling scala-gatling


    【解决方案1】:

    使用jsonStringify(),参见documentation。

    val jsonFileFeeder = jsonFile("requests.json").circular
    
    val scn = scenario("cost estimation")
      .feed(jsonFileFeeder)
      .exec(
        http("request_1")
          .post("/")
          .body(StringBody(
            """{
        "a":  "${a.jsonStringify()}"
    }"""
          )).asJson
      )
    

    【讨论】:

      猜你喜欢
      • 2015-12-11
      • 2017-03-21
      • 2020-03-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-26
      • 2021-04-13
      • 2020-01-16
      相关资源
      最近更新 更多