Skip to content

Commit b79e9de

Browse files
author
adriancole
committed
Decoders no longer read methodKey
1 parent 37462aa commit b79e9de

10 files changed

Lines changed: 19 additions & 23 deletions

File tree

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
### Version 3.0
22
* decoupled ErrorDecoder from fallback handling
33
* Decoders can throw checked exceptions, but needn't declare Throwable
4+
* Decoders no longer read methodKey
45

56
### Version 2.0.0
67
* removes guava and jax-rs dependencies

feign-core/src/main/java/feign/FeignException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ static FeignException errorReading(Request request, Response response, IOExcepti
3434
public static FeignException errorStatus(String methodKey, Response response) {
3535
String message = format("status %s reading %s", response.status(), methodKey);
3636
try {
37-
Object body = toString.decode(methodKey, response, String.class);
37+
Object body = toString.decode(response, String.class);
3838
if (body != null) {
3939
response = Response.create(response.status(), response.reason(), response.headers(), body.toString());
4040
message += "; content:\n" + body;

feign-core/src/main/java/feign/MethodHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ private SynchronousMethodHandler(Target<?> target, Client client, Provider<Retry
7171
} else if (metadata.returnType() == void.class) {
7272
return null;
7373
}
74-
return decoder.decode(metadata.configKey(), response, metadata.returnType());
74+
return decoder.decode(response, metadata.returnType());
7575
}
7676
}
7777

feign-core/src/main/java/feign/codec/Decoder.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
* }
3939
*
4040
* &#064;Override
41-
* public Object decode(String methodKey, Reader reader, Type type) {
41+
* public Object decode(Reader reader, Type type) {
4242
* return gson.fromJson(reader, type);
4343
* }
4444
* }
@@ -61,20 +61,19 @@ public abstract class Decoder {
6161
* opposed to just the {@link feign.Response.Body} when decoding into a new
6262
* instance of {@code type}.
6363
*
64-
* @param methodKey {@link feign.Feign#configKey} of the java method that invoked the request. ex. {@code IAM#getUser()}
6564
* @param response HTTP response.
6665
* @param type Target object type.
6766
* @return instance of {@code type}
6867
* @throws IOException if there was a network error reading the response.
6968
* @throws Exception if the decoder threw a checked exception.
7069
*/
71-
public Object decode(String methodKey, Response response, Type type) throws Exception {
70+
public Object decode(Response response, Type type) throws Exception {
7271
Response.Body body = response.body();
7372
if (body == null)
7473
return null;
7574
Reader reader = body.asReader();
7675
try {
77-
return decode(methodKey, reader, type);
76+
return decode(reader, type);
7877
} finally {
7978
ensureClosed(body);
8079
}
@@ -84,14 +83,12 @@ public Object decode(String methodKey, Response response, Type type) throws Exce
8483
* Implement this to decode a {@code Reader} to an object of the specified
8584
* type.
8685
*
87-
* @param methodKey {@link feign.Feign#configKey} of the java method that invoked the request.
88-
* ex. {@code IAM#getUser()}
89-
* @param reader no need to close this, as {@link #decode(String, Response, Type)}
86+
* @param reader no need to close this, as {@link #decode(Response, Type)}
9087
* manages resources.
9188
* @param type Target object type.
9289
* @return instance of {@code type}
9390
* @throws IOException will be propagated safely to the caller.
9491
* @throws Exception if the decoder threw a checked exception.
9592
*/
96-
public abstract Object decode(String methodKey, Reader reader, Type type) throws Exception;
93+
public abstract Object decode(Reader reader, Type type) throws Exception;
9794
}

feign-core/src/main/java/feign/codec/Decoders.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public static <T> Decoder transformFirstGroup(String pattern, final ApplyFirstGr
6767
checkNotNull(applyFirstGroup, "applyFirstGroup");
6868
return new Decoder() {
6969
@Override
70-
public Object decode(String methodKey, Reader reader, Type type) throws IOException {
70+
public Object decode(Reader reader, Type type) throws IOException {
7171
Matcher matcher = patternForMatcher.matcher(Decoders.toString(reader));
7272
if (matcher.find()) {
7373
return applyFirstGroup.apply(matcher.group(1));
@@ -113,7 +113,7 @@ public static <T> Decoder transformEachFirstGroup(String pattern, final ApplyFir
113113
checkNotNull(applyFirstGroup, "applyFirstGroup");
114114
return new Decoder() {
115115
@Override
116-
public List<T> decode(String methodKey, Reader reader, Type type) throws IOException {
116+
public List<T> decode(Reader reader, Type type) throws IOException {
117117
Matcher matcher = patternForMatcher.matcher(Decoders.toString(reader));
118118
List<T> result = new ArrayList<T>();
119119
while (matcher.find()) {
@@ -145,7 +145,7 @@ public static Decoder eachFirstGroup(String pattern) {
145145
}
146146

147147
private static String toString(Reader reader) throws IOException {
148-
return TO_STRING.decode(null, reader, null).toString();
148+
return TO_STRING.decode(reader, null).toString();
149149
}
150150

151151
private static final StringDecoder TO_STRING = new StringDecoder();

feign-core/src/main/java/feign/codec/SAXDecoder.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ protected SAXDecoder(SAXParserFactory factory) {
5050
}
5151

5252
@Override
53-
public Object decode(String methodKey, Reader reader, Type type) throws IOException, SAXException,
54-
ParserConfigurationException {
53+
public Object decode(Reader reader, Type type) throws IOException, SAXException, ParserConfigurationException {
5554
ContentHandlerWithResult handler = typeToNewHandler(type);
5655
checkState(handler != null, "%s returned null for type %s", this, type);
5756
XMLReader xmlReader = factory.newSAXParser().getXMLReader();

feign-core/src/main/java/feign/codec/StringDecoder.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,20 @@ public class StringDecoder extends Decoder {
3232

3333
// overridden to throw only IOException
3434
@Override
35-
public Object decode(String methodKey, Response response, Type type) throws IOException {
35+
public Object decode(Response response, Type type) throws IOException {
3636
Response.Body body = response.body();
3737
if (body == null)
3838
return null;
3939
Reader reader = body.asReader();
4040
try {
41-
return decode(methodKey, reader, type);
41+
return decode(reader, type);
4242
} finally {
4343
ensureClosed(body);
4444
}
4545
}
4646

4747
@Override
48-
public Object decode(String methodKey, Reader from, Type type) throws IOException {
48+
public Object decode(Reader from, Type type) throws IOException {
4949
StringBuilder to = new StringBuilder();
5050
CharBuffer buf = CharBuffer.allocate(BUF_SIZE);
5151
while (from.read(buf) != -1) {

feign-core/src/test/java/feign/FeignTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ public void doesntRetryAfterResponseIsSent() throws IOException, InterruptedExce
146146
return ImmutableMap.<String, Decoder>of("TestInterface", new Decoder() {
147147

148148
@Override
149-
public Object decode(String methodKey, Reader reader, Type type) throws IOException {
149+
public Object decode(Reader reader, Type type) throws IOException {
150150
throw new IOException("error reading response");
151151
}
152152

feign-core/src/test/java/feign/examples/GitHubExample.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ static class GsonModule {
7676
final Decoder jsonDecoder = new Decoder() {
7777
Gson gson = new Gson();
7878

79-
@Override public Object decode(String methodKey, Reader reader, Type type) {
79+
@Override public Object decode(Reader reader, Type type) {
8080
return gson.fromJson(reader, type);
8181
}
8282
};
@@ -94,8 +94,7 @@ static class JacksonModule {
9494
final Decoder jsonDecoder = new Decoder() {
9595
ObjectMapper mapper = new ObjectMapper().disable(FAIL_ON_UNKNOWN_PROPERTIES).setVisibility(FIELD, ANY);
9696

97-
@Override public Object decode(String methodKey, Reader reader, final Type type)
98-
throws JsonProcessingException, IOException {
97+
@Override public Object decode(Reader reader, final Type type) throws JsonProcessingException, IOException {
9998
return mapper.readValue(reader, mapper.constructType(type));
10099
}
101100
};

feign-jaxrs/src/test/java/feign/jaxrs/examples/GitHubExample.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ static class GitHubModule {
7171
final Decoder jsonDecoder = new Decoder() {
7272
Gson gson = new Gson();
7373

74-
@Override public Object decode(String methodKey, Reader reader, Type type) {
74+
@Override public Object decode(Reader reader, Type type) {
7575
return gson.fromJson(reader, type);
7676
}
7777
};

0 commit comments

Comments
 (0)