type mismatch with bodyString.transform

72 views
Skip to first unread message

pizza...@gmail.com

unread,
Mar 27, 2015, 2:42:09 PM3/27/15
to gat...@googlegroups.com
Hi I'm trying to convert json to a map using gatlings bodyString.transform.  I'm getting a type mismatch error

 found   : Option[String] => Option[scala.collection.mutable.Map[String,String]]

 

 required
: String => ?

.

post(s"api/v1/$user/account")
       
.queryParam("callback", "hopCallback")
       
.queryParam("commonDomain", commonDomain)
       
.check(status is 200)
       
.check(jsonPath("$.submitUrl").saveAs("hopSubmitUrl"))
       
.check(bodyString.transform(convertHOPJsonToMap).saveAs("hopData"))
       
.check(jsonPath("$.currentTime").exists)


where:
def convertHOPJsonToMap(in: Option[String]): Option[mutable.Map[String, String]] = in match {
   
case Some(json) => {

Stéphane LANDELLE

unread,
Mar 27, 2015, 4:14:26 PM3/27/15
to gat...@googlegroups.com
Don't bother, let Gatling do the job with "ofType": http://gatling.io/docs/2.1.4/http/http_check.html?highlight=jsonpath

check(jsonPath("$").ofType[Map[String, Any].saveAs("hopData")

Stéphane Landelle
Lead developer


--
You received this message because you are subscribed to the Google Groups "Gatling User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gatling+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Chuck D

unread,
Mar 27, 2015, 5:35:36 PM3/27/15
to gat...@googlegroups.com
hm, but i still need to convert.

def convertHOPJsonToMap(in: Option[String]): Option[mutable.Map[String, String]] = in match {
    case Some(json) => {
      val parsed = JSONValue.parse(json).asInstanceOf[JSONObject]
      val fields = parsed.get("fields").asInstanceOf[JSONArray]

      val result = mutable.Map[String, String]()

      for (i <- 0 until fields.size) {
        val f = fields.get(i).asInstanceOf[JSONObject]
        if (f.get("name") != null && f.get("value") != null) {
          result.put(f.get("name").toString, f.get("value").toString)
        }
      }

      Option(result)
    }
    case None => throw new Exception("No json value.")
  }

--
You received this message because you are subscribed to a topic in the Google Groups "Gatling User Group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/gatling/VB4P4VirYjk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to gatling+u...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages