I'm using Spring 5 WebClient test features and would like to extract body matched by the jsonPath
expression but can't find any suitable way of doing it. For example (the code is in Kotlin but I hope this doesn't make any difference):
client!!.get().uri("/app/metrics")
.accept(MediaType.APPLICATION_JSON_UTF8)
.exchange()
.expectStatus().isOk
.expectBody()
.jsonPath("$.names")
.isArray
The actual json body is:
{
"names": [
"jvm.buffer.memory.used",
"jvm.memory.used",
"jvm.buffer.count",
"jvm.gc.memory.allocated",
"logback.events",
"process.uptime",
"jvm.memory.committed",
"system.load.average.1m",
"jvm.gc.max.data.size",
"jvm.buffer.total.capacity",
"jvm.memory.max",
"system.cpu.count",
"jvm.threads.daemon",
"system.cpu.usage",
"jvm.threads.live",
"process.start.time",
"jvm.threads.peak",
"jvm.gc.live.data.size",
"jvm.gc.memory.promoted",
"process.cpu.usage"
]
}
So I'd like to get list of names into list variable and use it. Is there any way to do it with current jsonPath
support?