小编Art*_*lin的帖子

从Spring WebFlux返回Flux <String>会返回一个字符串而不是JSON中的字符串数组

Spring WebFlux的新手,试图在一个端点返回字符串数组,并且由于某种原因它返回一个连接字符串而不是JSON数组.

用一些类包装它可以解决问题,但想知道如何实际返回字符串数组?例如,返回Array<String>按预期工作

class Wrapper(val data: String) {

@RestController
class Test() {
     @RequestMapping("/wrapped") // Returns valid JSON array: [{"value":"Hello"},{"value":"World"}]
     fun b() = Flux.just(Wrapper("Hello"),Wrapper("World"))
     @RequestMapping("/raw") // Returns not valid JSON with just one concatenated string: HelloWorld
     fun a() = Flux.just("Hello", "World")
}
Run Code Online (Sandbox Code Playgroud)

kotlin spring-boot spring-webflux

5
推荐指数
1
解决办法
1895
查看次数

标签 统计

kotlin ×1

spring-boot ×1

spring-webflux ×1