Commit ac86e779 by Spencer Gibb

Fix Feign ResponseEntity<Void> NPE

fixes gh-539
parent 13a3ea07
......@@ -39,8 +39,12 @@ public class ResponseEntityDecoder implements Decoder {
type = ((ParameterizedType) type).getActualTypeArguments()[0];
Object decodedObject = decoder.decode(response, type);
Class<?> clazz = null;
if (decodedObject != null) {
clazz = decodedObject.getClass();
}
return createResponse(
decodedObject.getClass(),
clazz,
decodedObject,
response);
}
......@@ -56,9 +60,11 @@ public class ResponseEntityDecoder implements Decoder {
headers.put(key, new LinkedList<>(response.headers().get(key)));
}
return new ResponseEntity<T>(
clazz.cast(instance),
headers,
T retVal = null;
if (clazz != null && instance != null) {
retVal = clazz.cast(instance);
}
return new ResponseEntity<>(retVal, headers,
HttpStatus.valueOf(response.status()));
}
}
\ No newline at end of file
......@@ -95,6 +95,17 @@ public class SpringDecoderTests extends FeignClientFactoryBean {
assertEquals("first hello didn't match", "hello world 1", hellos.get(0));
}
@Test
public void testResponseEntityVoid() {
ResponseEntity<Void> response = testClient().getHelloVoid();
assertNotNull("response was null", response);
List<String> headers = response.getHeaders().get("X-test-header");
assertNotNull("headers was null", headers);
assertEquals("headers size was wrong", 1, headers.size());
String header = headers.get(0);
assertEquals("header was wrong", "myval", header);
}
@Data
@AllArgsConstructor
@NoArgsConstructor
......@@ -114,6 +125,9 @@ public class SpringDecoderTests extends FeignClientFactoryBean {
@RequestMapping(method = RequestMethod.GET, value = "/hellostrings")
public List<String> getHelloStrings();
@RequestMapping(method = RequestMethod.GET, value = "/hellovoid")
public ResponseEntity<Void> getHelloVoid();
}
@Configuration
......@@ -127,6 +141,11 @@ public class SpringDecoderTests extends FeignClientFactoryBean {
}
@Override
public ResponseEntity<Void> getHelloVoid() {
return ResponseEntity.noContent().header("X-test-header", "myval").build();
}
@Override
public Hello getHello() {
return new Hello("hello world 1");
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment