1
我有一個簡單的控制器反序列化錯誤春季啓動反應
@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>