【问题标题】:De-serialization error spring boot reactive反序列化错误弹簧启动反应
【发布时间】: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


    【解决方案1】:

    您现在实际上正在使用 Spring MVC。

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

    【讨论】:

      猜你喜欢
      • 2016-11-10
      • 2021-06-27
      • 1970-01-01
      • 1970-01-01
      • 2021-08-12
      • 2015-08-18
      • 1970-01-01
      • 2019-03-28
      • 2018-07-03
      相关资源
      最近更新 更多