Skip to content

Commit 073e54e

Browse files
author
adriancole
committed
Remove overrides = true on codec modules
1 parent c6b2a59 commit 073e54e

8 files changed

Lines changed: 38 additions & 31 deletions

File tree

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
### Version 4.3
22
* Add ability to configure zero or more RequestInterceptors.
3+
* Remove `overrides = true` on codec modules.
34

45
### Version 4.2/3.3
56
* Document and enforce JAX-RS annotation processing from server POV

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ The `GsonModule` in the `feign-gson` extension configures a (`Decoder.TextStream
137137

138138
Here's how you could write this yourself, using whatever library you prefer:
139139
```java
140-
@Module(overrides = true, library = true)
140+
@Module(library = true)
141141
static class JsonModule {
142142
@Provides(type = SET) Decoder decoder(final JsonParser parser) {
143143
return new Decoder.TextStream<Object>() {
@@ -215,7 +215,7 @@ If you have to only grab a single field from a server response, you may find reg
215215

216216
Here's how our IAM example grabs only one xml element from a response.
217217
```java
218-
@Module(overrides = true, library = true)
218+
@Module(library = true)
219219
static class IAMModule {
220220
@Provides(type = SET) Decoder arnDecoder() {
221221
return Decoders.firstGroup("<Arn>([\\S&&[^<]]+)</Arn>");

core/src/main/java/feign/Feign.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -124,18 +124,6 @@ public static class Defaults {
124124
return new Options();
125125
}
126126

127-
@Provides Set<Encoder> noEncoders() {
128-
return Collections.emptySet();
129-
}
130-
131-
@Provides Set<Decoder> noDecoders() {
132-
return Collections.emptySet();
133-
}
134-
135-
@Provides Set<IncrementalDecoder> noIncrementalDecoders() {
136-
return Collections.emptySet();
137-
}
138-
139127
/**
140128
* Used for both http invocation and decoding when observers are used.
141129
*/

core/src/main/java/feign/ReflectiveFeign.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@
3333
import java.lang.reflect.Proxy;
3434
import java.lang.reflect.Type;
3535
import java.util.Collection;
36+
import java.util.Collections;
3637
import java.util.HashMap;
3738
import java.util.LinkedHashMap;
38-
import java.util.LinkedHashSet;
3939
import java.util.List;
4040
import java.util.Map;
4141
import java.util.Map.Entry;
@@ -109,7 +109,19 @@ static class FeignInvocationHandler implements InvocationHandler {
109109
@dagger.Module(complete = false, injects = {Feign.class, MethodHandler.Factory.class}, library = true)
110110
public static class Module {
111111
@Provides(type = Provides.Type.SET_VALUES) Set<RequestInterceptor> noRequestInterceptors() {
112-
return new LinkedHashSet<RequestInterceptor>();
112+
return Collections.emptySet();
113+
}
114+
115+
@Provides(type = Provides.Type.SET_VALUES) Set<Encoder> noEncoders() {
116+
return Collections.emptySet();
117+
}
118+
119+
@Provides(type = Provides.Type.SET_VALUES) Set<Decoder> noDecoders() {
120+
return Collections.emptySet();
121+
}
122+
123+
@Provides(type = Provides.Type.SET_VALUES) Set<IncrementalDecoder> noIncrementalDecoders() {
124+
return Collections.emptySet();
113125
}
114126

115127
@Provides Feign provideFeign(ReflectiveFeign in) {

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

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ void login(
9090

9191
@RequestLine("POST /") Observable<Response> observableResponse();
9292

93-
@dagger.Module(overrides = true, library = true)
93+
@dagger.Module(library = true)
9494
static class Module {
9595
@Provides(type = SET) Encoder defaultEncoder() {
9696
return new Encoder.Text<Object>() {
@@ -108,14 +108,6 @@ static class Module {
108108
};
109109
}
110110

111-
// just run synchronously
112-
@Provides @Singleton @Named("http") Executor httpExecutor() {
113-
return new Executor() {
114-
@Override public void execute(Runnable command) {
115-
command.run();
116-
}
117-
};
118-
}
119111
}
120112
}
121113

@@ -126,7 +118,8 @@ public void observableVoid() throws IOException, InterruptedException {
126118
server.play();
127119

128120
try {
129-
TestInterface api = Feign.create(TestInterface.class, "http://localhost:" + server.getPort(), new TestInterface.Module());
121+
TestInterface api = Feign.create(TestInterface.class, "http://localhost:" + server.getPort(),
122+
new TestInterface.Module(), new RunSynchronous());
130123

131124
final AtomicBoolean success = new AtomicBoolean();
132125

@@ -160,7 +153,8 @@ public void observableResponse() throws IOException, InterruptedException {
160153
server.play();
161154

162155
try {
163-
TestInterface api = Feign.create(TestInterface.class, "http://localhost:" + server.getPort(), new TestInterface.Module());
156+
TestInterface api = Feign.create(TestInterface.class, "http://localhost:" + server.getPort(),
157+
new TestInterface.Module(), new RunSynchronous());
164158

165159
final AtomicBoolean success = new AtomicBoolean();
166160

@@ -187,14 +181,26 @@ public void observableResponse() throws IOException, InterruptedException {
187181
}
188182
}
189183

184+
@Module(library = true, overrides = true)
185+
static class RunSynchronous {
186+
@Provides @Singleton @Named("http") Executor httpExecutor() {
187+
return new Executor() {
188+
@Override public void execute(Runnable command) {
189+
command.run();
190+
}
191+
};
192+
}
193+
}
194+
190195
@Test
191196
public void incrementString() throws IOException, InterruptedException {
192197
final MockWebServer server = new MockWebServer();
193198
server.enqueue(new MockResponse().setResponseCode(200).setBody("foo"));
194199
server.play();
195200

196201
try {
197-
TestInterface api = Feign.create(TestInterface.class, "http://localhost:" + server.getPort(), new TestInterface.Module());
202+
TestInterface api = Feign.create(TestInterface.class, "http://localhost:" + server.getPort(),
203+
new TestInterface.Module(), new RunSynchronous());
198204

199205
final AtomicBoolean success = new AtomicBoolean();
200206

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ static class GitHubModule {
9797
/**
9898
* Here's how it looks to wire json codecs. Note, that you can always instead use {@code feign-gson}!
9999
*/
100-
@Module(overrides = true, library = true)
100+
@Module(library = true)
101101
static class GsonModule {
102102

103103
@Provides @Singleton Gson gson() {

core/src/test/java/feign/examples/IAMExample.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ private IAMTarget(String accessKey, String secretKey) {
6363
}
6464
}
6565

66-
@Module(overrides = true, library = true)
66+
@Module(library = true)
6767
static class IAMModule {
6868
@Provides(type = SET) Decoder decoder() {
6969
return Decoders.firstGroup("<Arn>([\\S&&[^<]]+)</Arn>");

gson/src/main/java/feign/gson/GsonModule.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343

4444
import static dagger.Provides.Type.SET;
4545

46-
@dagger.Module(library = true, overrides = true)
46+
@dagger.Module(library = true)
4747
public final class GsonModule {
4848

4949
@Provides(type = SET) Encoder encoder(GsonCodec codec) {

0 commit comments

Comments
 (0)