Passing a List in request body for POST call

I am trying to make a POST call:

I have a dynamically generated list of strings:

val resourceList = session(“resourceNames”).as[List[String]].mkString(",")

Now I need to pass this as request body:

.exec(http(“Submit Resources List”)
.post("/my-api-endpoint")
.body(StringBody("""["${resourcesForApp}"]""")).asJSON
.check(status.is(200))
)

Basically the Rest body should look like:

[“resource1”, “resource2”, “resource3”]

But my Java API is reading the request body as a single element in the list seperated by comma instead of reading 3 elements in the list as above.

How to correctly set the body in gatling request?

*** resourcesForApp has been set in session for val resourceList.
session.set(“resourcesForApp”, resourceList)

At some point you will need to transform from a list to a string. The default transformation doesn’t quote the elements, which is what you are seeing. So you will have to do a non-default transformation. Instead of sending in an expression to StringBody, send in a session function, and have that function return the list converted to a JSON array.