Using Gatling 2.2.0 (pre-release version)
There an API that contains locations which is Hash/Map of String to Int. I have saved this into a session attribute. I am trying to extract the keys from this Hash for building out other API calls. But, I am getting stuck extracting the value from the session attribute.
JSON:
"locations": {
"/href/10592": 373,
"/href/10663": 6032,
...
}
Using
.check(jsonPath("$.locations").find.saveAs("locs"))
Using println, I can see that this Session attribute looks like:
locs -> {"/href/10592":373,"/href/10663":6032, ...}
To me, this locs looks like a Map[String, Int] .
But, when I get the session attribute back, and try to convert it into a Map[String, Int], it looks like it being stored as a String, which cannot be cast into a Map.
var locMap = session("locs").as[Map[String,Int]] // ------> class cast exception
[ERROR] [04/19/2016 21:18:20.947] [GatlingSystem-akka.actor.default-dispatcher-6] [akka://GatlingSystem/user/sessionHook-2] java.lang.String cannot be cast to scala.collection.immutable.Map
java.lang.ClassCastException: java.lang.String cannot be cast to scala.collection.immutable.Map
at com.company.IllBFS$$anonfun$1.apply(IlBFS.scala:56)
at com.company.IllBFS$$anonfun$1.apply(IlBFS.scala:55)
at io.gatling.core.action.SessionHook.executeOrFail(SessionHook.scala:46)
at io.gatling.core.action.Failable$class.execute(Actions.scala:71)
I think that the json element (of type String) has to be evaluated into an Map object before passing it into saveAs(). For that, I guess I need to use a transform before the saveAs to correctly convert the JSON-string into a Hash. Is this correct reasoning?
Thanks in advance for any advice.