Skip to content

Commit

Permalink
Update code as per suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
gromspys committed Oct 11, 2023
1 parent ac5af83 commit bffdd7e
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions reactive/src/main/java/feign/reactive/ReactiveDecoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import feign.FeignException;
import feign.Response;
import feign.Types;
import feign.codec.DecodeException;
import feign.codec.Decoder;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
Expand All @@ -37,12 +38,18 @@ public Object decode(Response response, Type type) throws IOException, FeignExce
Class<?> rawType = Types.getRawType(type);
if (rawType.isAssignableFrom(Mono.class)) {
Type lastType = Types.resolveLastTypeParameter(type, Mono.class);
return Mono.just(delegate.decode(response, lastType));
return Mono.fromCallable(() -> delegate.decode(response, lastType));
}
if (rawType.isAssignableFrom(Flux.class)) {
Type lastType = Types.resolveLastTypeParameter(type, Flux.class);
Type listType = Types.parameterize(List.class, lastType);
return Flux.fromIterable((Iterable)delegate.decode(response, listType));
Object decoded = delegate.decode(response, listType);
if (decoded instanceof Iterable) {
return Flux.fromIterable((Iterable) decoded);
} else {
String errorMessage = "Expected type Iterable, but was: " + decoded.getClass();
throw new DecodeException(response.status(), errorMessage, response.request());
}
}

return delegate.decode(response, type);
Expand Down

0 comments on commit bffdd7e

Please sign in to comment.