How to solve "Can't cast attribute ' cursorID' of type class java.lang.String into class scala.Option?

// initialize
exec(session => session.set("CursorID", "")
// loop
.doWhile(#{CursorID.exists()}) {
  exec(http("Test:Cursor Pagination")
    .get("/test")
    .queryParam("sortField", "ID")
    .queryParam("limit", 100)
    .queryParam("cursor", "#{CursorID}")
    .check(status.is(200))
    .check(jsonPath("$.nextCursor").optional.saveAs("NextCursorID"))
  )
  .exec { session =>
    session("NextCursorID").asOption[String] match {
      case Some(nextCursorID) =>
           session
              // update cursor
             .set("CursorID", nextCursorID)
             // remove so we're sure to test the fresh value on next iteration
             .remove("NextCursorID")
      case _ =>
          // end of loop, remove cursor
          session.remove("CursorID")
   }
  }
}
1 Like