反序列化错误弹簧启动反应

时间:2017-08-31 18:27:43

标签: spring spring-boot jackson reactor spring-webflux

我有一个简单的控制器

@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有反应堆类型(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>

1 个答案:

答案 0 :(得分:4)

你现在正在使用Spring MVC。

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