反序列化错误春季启动反应
问题描述:
我有一个简单的控制器反序列化错误春季启动反应
@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
是否具有用于反应堆类型(单声道,通量)的默认自动解串器?
我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
并确保没有其他依赖项能够传递它。