【发布时间】:2018-02-09 19:00:30
【问题描述】:
我有一个简单的控制器
@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
}
...
}
调用此网址时出现异常
"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 类型(单声道、通量)的默认自动反序列化器吗?
我的 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 spring-boot jackson reactor spring-webflux