反序列化错误 spring 引导反应

De-serialization error spring boot reactive

我有一个简单的控制器

@RestController
@RequestMapping("path")
public class MyController {

    @PostMapping(consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
    public Flux<SomeObject> run(@RequestBody Flux<RequestObject> request){

        //do something and return flux
    }
    ...
}

在调用此 url 时出现异常

"Type definition error: [simple type, class reactor.core.publisher.Flux]; nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Can not construct instance of reactor.core.publisher.Flux (no Creators, like default construct, exist): abstract types either need to be mapped to concrete types, have custom deserializer, or contain additional type information\n at [Source: (PushbackInputStream); line: 1, column: 1]

我理解这个错误,通常我会添加一个 如果需要注释

@JsonDeserialize(as = SomeConcreteClass.class)

但在这种情况下,我应该绑定哪个 Flux 具体示例?另外,Spring boot 没有针对 Reactor 类型(Mono、Flux)的默认自动反序列化器吗?

我的 pom(相关内容):

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-webflux</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-commons</artifactId>
    </dependency>

您实际上正在使用 Spring MVC。

删除 spring-boot-starter-web 并确保没有其他依赖项传递它。