I'm trying to compile a string like :
val route = "this/is/my/url/${body2.id}"
where body2 is a json response from a previous request.
So I tried to compile this string with :
val routeExpression = (route).el[String]
And I saw on this question : Getting the String out of a Gatling expression
I should do something like :
def getRoute = {
routeExpression.map { route => route }
}
but this function return a Validation[Expression[String]]. How could I get the string compiled ?
Cheers.
Finally the problem was not the one asking. In fact I was saving all the json inside the session. But the problem was gatling expression like ${body2.id} works only if the session attribute is like :
Map(body2 -> Map(id -> 45787))
but mine was
Map(body2 -> "{ id: 45787 }")
so I used Jackson library to parse my json to convert it to a map, and it solved the problem.
Just have to specify the type as Stephane Landelle said :
check(jsonPath("$").ofType[Map[String, Any]].saveAs("myJson"))