4
votes

I'm trying to return an Observable from a Spring RestController without any success. My code is the following:

@RestController
public class HystrixCommentController {

    @GetMapping(value = "/com1/{id}")
    public Observable<Comment> getComment1(@PathVariable int id) {
        return Observable.just(new Comment());
    }
}

When run the request in postman I alway get the following error :

{
  "timestamp": "2018-07-08T16:07:36.809+0000",
  "status": 500,
  "error": "Internal Server Error",
  "message": "No converter found for return value of type: class rx.internal.util.ScalarSynchronousObservable",
  "path": "/com1/1"
}
  • Doesn't SpringBoot 2 also support rx.Observable in the RestController like they do with Mono/Flux ?

  • Do I need to transform manually the Observable to a Mono/Flux ?

Regards

Note: spring-boot-starter-webflux is included in the pom

I tried this :

@RestController
    public class HystrixCommentController {

        @GetMapping(value = "/com1/{id}", produces = "application/json")
            public Observable<Comment> getComment1(@PathVariable int id) {
            return Observable.just(new Comment());
        }

}

With no success :

{
    "timestamp": "2018-07-08T18:21:42.918+0000",
    "status": 406,
    "error": "Not Acceptable",
    "message": "Could not find acceptable representation",
    "path": "/com1/1"
}
1
Have you seen this? stackoverflow.com/questions/42748775/… You might just be missing a dependency! - Dovmo
Yes ! you are right ... the missing dependency was the problem . Thanks ! - François-David Lessard

1 Answers

3
votes

So the problem here was the missing dependency in my pom.xml :

<dependency>
    <groupId>io.reactivex</groupId>
    <artifactId>rxjava-reactive-streams</artifactId>
    <version>1.2.1</version>
</dependency>

Thanks to @Dovmo for finding the issue