简体   繁体   中英

Gatling - convert json response to List of case classes

Gatling 2.0. I'receiving from server the following json of Events:

[  
   {  "a":"a","b":"b","c":"c","d":"d"},
   {  "a":"a1","b":"b1","c":"c1","d":"d2" },
   { "a":"a2","b":"b2","c":"c2","d":"d3" }
]

Now I would like to store it in session as List of Event classes

case class Event(a:String:b:String,d:String)

I'm trying to do the following

jsonPath("$.chats.chat[0].events.event").ofType[Seq[Any]].transform(_.map{ l =>

                Some(Event(l(0).asInstanceOf[String], l(1).asInstanceOf[String],l(3).asInstanceOf[String])).saveAs("events")

but this line does not compile: Please help.

  1. after it I would like to fetch this list from session, Can i do it by:

    val events = session("events").as[Seq[Events]]

Thanks.

You're using transform , which takes the extract result and transform it into something else.

Here, as you don't specify the check ordinality, you use the default, find , that only get you the first result of the extraction step. I doubt $.chats.chat[0].events.event is what you want, it would probably return a Map (a javascript Object). You probably want $.chats.chat[0].events .

Then regarding, storing and accessing data into the Session, you shouldn't try storing them in classes if you're not used to Scala.

Instead, upgrade to Gatling 2.1 that has improved EL capabilities, so you can write things like ${event.foo.bar} (which you can't with Gatling 2.0).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM