Home > Back-end >  How do I have to format my feeder csv file, to inject a list of string elements into my JSON request
How do I have to format my feeder csv file, to inject a list of string elements into my JSON request

Time:05-19

I am having trouble adding a list of string id's to my JSON request body! I tried many different formatting styles ... but could not figure out how to get this to work in Gatling, using the JavaDSL.

this is one of my csv formatting attempts to represent a list:

playerId, dateIds
113489013, {"20210820TT", "20220211TT"}

here the code to feed my csv data into the json request body:

public static ScenarioBuilder isPlayingScenario = scenario("is playing")
            .feed(playerIdFeeder)
            .exec(isPlaying);

public static final ChainBuilder isPlaying =
        exec(http(IS_PLAYING)
                .post(IS_PLAYING_URL   "#{playerId}")
                .headers(headers)
                .body(ElFileBody("data/requests/is-playing-request.json"))
                .asJson()
        );

and here the the very simple request body only containing a list of id's:

{
  "dateIds": ["#{dateIds}"]
}

This particular attempt is resolved to:

body:StringChunksRequestBody{contentType='application/json', charset=UTF-8, content={
  "dateIds": [" {"20210820TT""]
}}

so it does neither resolve to a valid JSON, nor does it include the second id... Any help is well appreciated! Thanks.

CodePudding user response:

Please properly read the CSV specification, your file is malformed. In particular:

  1. Fields containing line breaks (CRLF), double quotes, and commas should be enclosed in double-quotes. For example:
  "aaa","b CRLF
  bb","ccc" CRLF
  zzz,yyy,xxx
  1. If double-quotes are used to enclose fields, then a double-quote appearing inside a field must be escaped by preceding it with another double quote. For example:

    "aaa","b""bb","ccc"

Your file should look like:

playerId, dateIds
113489013, "{""20210820TT"", ""20220211TT""}"
  • Related