.exec(session => {
println(s" This is the Content Value : ${session("contentValue").as[String]}")
session
})
in the console, it will print :
This is the Content Value :
{"resources":{"resourceRoots":{
......
.....
:{"targetMappings":{"baseUrl":"/baseurl2,"cacheId":"mycacheid"},"personalization":{"baseUrl":"/url1","relativeUrl":"bar","cacheId":"mycacheid1"},"pbFioriHome":{"baseUrl":"/fullpath/url","cacheId":"mycacheid2"},"startUp":{"baseUrl":"/homepage","relativeUrl":"start_up","cacheId":"mycacheid3"}},"toto2":true"}}
So, how to parse my saved user session’s value contentCache?
i’ve tried with transformwithSession but with no luck.
[ERROR] i.g.c.a.b.SessionHookBuilder$$anon$1 - 'hook-5' crashed with 'j.u.NoSuchElementException: No attribute named 'cacheId' is defined', forwarding to the next one
---- Errors --------------------------------------------------------------------
> jsonPath($..cacheid).find.transform.exists preparation crashed 1 (100,0%)
: Jackson failed to parse into a valid AST: c.f.j.c.JsonParseE...
I’ve rechecked it, however i think i need to understand, if the string retreived with the CSS Selector, can be parsed via json even if it is encoded as “HTML entity”.
so that’s why i first tried to save it, and try to extract the json element i’m looking for and save it…
Maybe, it’s not required to save it first, but i don’t really have better idea.
however, when i don’t run the transform, i have the whole json, but if i transform (no matter if i try css => json.jsonPath -that is bringing an error - or something else) when i print the content value i have :
This is the Content Value : io.gatling.core.check.jsonpath.JsonPathCheckBuilder$$anon$1@7c462bab
definitively, i don’t understand…
i was also looking for differents type, in the cheat sheet (like in the gatling academy course) but there is no more cheat sheet (or i didn’t find it).
No. jsonPath is a Gatling check, not an arbitrary JSON parser. You can’t use Gatling components in your own functions. You have to use standard Java libraries.
OK, i create a package “org.mypackage” and when i run it in java, i still need to include other jars (even if they are included in my jar file “DecodeAndJSONParse” )
The function works as following :
class org.mypackage.DecodeAndJSONParse is not a value
.transform(content => org.mypackage.DecodeAndJSONParse(content, “$…cacheId”)//.saveAs(“contentValue”)