1
votes

Goal: migration from Spring Boot 1.x (webMvc) to version 2 (webFlux) and Spring Cloud Edgware SR2 to FinchleyM8 (awaiting release version).

Problem: Feign -> OpenFeign. OpenFeign under the hood uses RxJava but WebFlux - Reactor3. At the current moment when I using Mono as returned type, I have got an error:

Caused by: org.springframework.http.converter.HttpMessageConversionException: Type definition error: [simple type, class reactor.core.publisher.Mono]; nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of reactor.core.publisher.Mono (no Creators, like default construct, exist): abstract types either need to be mapped to concrete types, have custom deserializer, or contain additional type information

Code example:

@FeignClient(name = "thirdpartyresource", url = "${third.party.resource.url}")
public interface ThirdPartyResource {

    @PostMapping(value = "/validate", consumes = APPLICATION_FORM_URLENCODED_VALUE)
    Mono<ValidationResultDto> validate(MultiValueMap multiValueMap); // WORKS BAD
    // Single<ValidationResultDto> validate(MultiValueMap multiValueMap); WORKS WELL
}

Question: Do I need to create my own converter Single to Mono or it's some problems of spring-cloud-starter-openfeign and all should work OOTB?

1
It does not out of the box. - spencergibb
Since Spring provides Reactor 3 as default, would be more suitable when projects from the Springs family also use it. Thanks - Ruslan
Thanks, guys! - Ruslan

1 Answers

0
votes

You can use those methods to adapt:

For Single rxJavaSingle

Mono.from(RxReactiveStreams.toPublisher(rxJavaSingle))

For Completable rxJavaCompletable Mono.from(RxReactiveStreams.toPublisher(rxJavaCompletable))