Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring WebClient提取JsonPath值_Spring_Spring Test_Spring Webflux_Spring Kotlin - Fatal编程技术网

Spring WebClient提取JsonPath值

Spring WebClient提取JsonPath值,spring,spring-test,spring-webflux,spring-kotlin,Spring,Spring Test,Spring Webflux,Spring Kotlin,我正在使用Spring5,希望提取与jsonPath表达式匹配的body,但找不到任何合适的方法。例如(代码在Kotlin中,但我希望这不会有任何区别): 实际的json正文是: { "names": [ "jvm.buffer.memory.used", "jvm.memory.used", "jvm.buffer.count", "jvm.gc.memory.allocated", "logback.events", "process.uptime", "jvm.memory.committ

我正在使用Spring5,希望提取与
jsonPath
表达式匹配的body,但找不到任何合适的方法。例如(代码在Kotlin中,但我希望这不会有任何区别):

实际的json正文是:

{
"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"
]
}

所以我想把名字列表放到列表变量中并使用它。当前的
jsonPath
支持有什么方法可以做到这一点吗?

类似的东西应该可以使用(在
springBootVersion='2.1.0.RELEASE'中试用过)

{
"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"
]
}
client.get().uri("/app/metrics")
    .accept(MediaType.APPLICATION_JSON_UTF8)
    .exchange()
    .expectStatus().isOk
    .expectBody()
    .jsonPath("$.names")
    .value<JSONArray> { json ->
        json.toList().forEach { println(it) }
    }
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