OptionalAwareDecoder in feign core?
See original GitHub issueHej again, How are the chances of getting a “feign-guava-optional” module (or similar) into feign that knows about 404-decoding Guava Optional? Such a module would have a Guava dependency and only make sense where decode404 is enabled. R.
/**
* Decorates a Feign {@link Decoder} such that it returns {@link Optional#absent} when observing an HTTP 404 error code
* for a method with {@link Type} {@link Optional}. Propagates the exception returned by the given {@link ErrorDecoder}
* in case the response is 404 for a non-Optional method.
*/
public final class OptionalAwareDecoder implements Decoder {
private final Decoder delegate;
private final ErrorDecoder errorDecoder;
public OptionalAwareDecoder(Decoder delegate, ErrorDecoder errorDecoder) {
this.delegate = delegate;
this.errorDecoder = errorDecoder;
}
@Override
public Object decode(Response response, Type type) throws IOException, FeignException {
if (response.status() == 404) {
if (Types.getRawType(type).equals(Optional.class)) {
return Optional.absent();
} else {
throw Throwables.propagate(errorDecoder.decode(null, response));
}
} else {
return delegate.decode(response, type);
}
}
}
Issue Analytics
- State:
- Created 8 years ago
- Reactions:6
- Comments:22 (18 by maintainers)
Top Results From Across the Web
Request.Options (Feign Core 12.1 API) - javadoc.io
Creates a new Options instance. Parameters: connectTimeoutMillis - connection timeout in milliseconds. readTimeoutMillis - read timeout in milliseconds.
Read more >feign.Types.getRawType java code examples - Tabnine
Best Java code snippets using feign.Types.getRawType (Showing top 14 results ... origin: com.netflix.feign/feign-core ... OptionalAwareDecoder.decode(...).
Read more >Spring Cloud OpenFeign
Feign is a declarative web service client. It makes writing web service clients easier. To use Feign create an interface and annotate it....
Read more >io.github.openfeign : feign-core - Maven Central
Version Updated OSS Index
V: 12.1 Updated: 18‑Nov‑2022 open_in_new
V: 12.0 Updated: 31‑Oct‑2022 open_in_new
V: 11.10 Updated: 21‑Sep‑2022 open_in_new
Read more >Intro to Feign | Baeldung
This article introduces Feign, a declarative HTTP client that simplifies ... Besides the feign-core dependency (which is also pulled in), ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
+1 for me, allthough I need support for Java 8 Optional, too.
+1 but it’s require a JDK 8