Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

De-serialization error spring boot reactive

I have a simple controller

@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
    }
    ...
}

On calling this url I'm getting the exception

"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]

I understand this error and usually, I would just add an annotation if needed

@JsonDeserialize(as = SomeConcreteClass.class)

But in this case, to which Flux concrete example should I bind? Also, Doesn't Spring boot has a default auto-deserializers for Reactor Types (Mono, Flux)?

My pom (relevant stuff):

    <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>
like image 667
royB Avatar asked Mar 09 '23 04:03

royB


1 Answers

You're actually using Spring MVC right now.

Remove the spring-boot-starter-web and make sure no other dependency brings it transitively.

like image 157
Brian Clozel Avatar answered Mar 16 '23 13:03

Brian Clozel