Prevent StackOverflowError in AbstractJackson2HttpMessageConverter

Issue: SPR-14520
This commit is contained in:
Sebastien Deleuze
2016-08-04 11:11:15 -07:00
parent fad931d764
commit e86529ec90
2 changed files with 35 additions and 3 deletions

View File

@@ -692,6 +692,25 @@ public class RequestResponseBodyMethodProcessorTests {
assertEquals("UTF-8", this.servletResponse.getCharacterEncoding());
}
@Test // SPR-14520
public void resolveArgumentTypeVariableWithGenericInterface() throws Exception {
this.servletRequest.setContent("\"foo\"".getBytes("UTF-8"));
this.servletRequest.setContentType(MediaType.APPLICATION_JSON_UTF8_VALUE);
Method method = MyControllerImplementingInterface.class.getMethod("handle", Object.class);
HandlerMethod handlerMethod = new HandlerMethod(new MyControllerImplementingInterface(), method);
MethodParameter methodParameter = handlerMethod.getMethodParameters()[0];
List<HttpMessageConverter<?>> converters = new ArrayList<>();
converters.add(new MappingJackson2HttpMessageConverter());
RequestResponseBodyMethodProcessor processor = new RequestResponseBodyMethodProcessor(converters);
String value = (String)processor.readWithMessageConverters(this.request, methodParameter,
methodParameter.getGenericParameterType());
assertEquals("foo", value);
}
private void assertContentDisposition(RequestResponseBodyMethodProcessor processor,
boolean expectContentDisposition, String requestURI, String comment) throws Exception {
@@ -1011,4 +1030,13 @@ public class RequestResponseBodyMethodProcessorTests {
}
}
interface MappingInterface<A> {
default A handle(@RequestBody A arg) {
return arg;
}
}
static class MyControllerImplementingInterface implements MappingInterface<String> {
}
}