Browse Source

ensure gson does not attempt to decode void

pull/69/head
adriancole 11 years ago
parent
commit
50e3cf54b7
  1. 2
      gson/src/main/java/feign/gson/GsonModule.java
  2. 16
      gson/src/test/java/feign/gson/GsonModuleTest.java

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

@ -103,7 +103,7 @@ public final class GsonModule {
} }
@Override public Object decode(Response response, Type type) throws IOException { @Override public Object decode(Response response, Type type) throws IOException {
if (response.body() == null) { if (void.class.equals(type) || response.body() == null) {
return null; return null;
} }
Reader reader = response.body().asReader(); Reader reader = response.body().asReader();

16
gson/src/test/java/feign/gson/GsonModuleTest.java

@ -133,6 +133,22 @@ public class GsonModuleTest {
}.getType()), zones); }.getType()), zones);
} }
@Test public void voidDecodesToNull() throws Exception {
DecoderBindings bindings = new DecoderBindings();
ObjectGraph.create(bindings).inject(bindings);
Response response = Response.create(200, "OK", Collections.<String, Collection<String>>emptyMap(), zonesJson);
assertEquals(bindings.decoder.decode(response, void.class), null);
}
@Test public void nullBodyDecodesToNull() throws Exception {
DecoderBindings bindings = new DecoderBindings();
ObjectGraph.create(bindings).inject(bindings);
Response response = Response.create(204, "OK", Collections.<String, Collection<String>>emptyMap(), null);
assertEquals(bindings.decoder.decode(response, String.class), null);
}
private String zonesJson = ""// private String zonesJson = ""//
+ "[\n"// + "[\n"//
+ " {\n"// + " {\n"//

Loading…
Cancel
Save