Datz
Datz

Reputation: 3881

Is it possible to make a Feign client to return an Optional<?> if the result could be null (dismiss404 = true)

I am using this Feign client

@FeignClient(name = "acme-service", url = "http://the-url", path = "/acme/", dismiss404 = true)
public interface AcmeServiceClient {
    @GetMapping("/{article}")
    Optional<AcmeDto> getArticle(@PathVariable final String article);
}

If the acme-service returns null, the getArticle method also returns null.

Is it possible to use an Optional<AcmeDto> as return type in this case?

Update with 13.5: no error, but null is returned instead of an empty Optional. (Previous: When I use it like this, I get an error that the result could not be converted into an Optional.)

Can I configure OpenFeign to support Optionals as return types?

Upvotes: 3

Views: 409

Answers (0)

Related Questions