Expose parameter annotations from interfaces across entire class hierarchy

Closes gh-24127
This commit is contained in:
Juergen Hoeller
2020-03-23 17:57:44 +01:00
parent 7ebd850b85
commit 1800b10717
2 changed files with 33 additions and 3 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -690,6 +690,27 @@ public class RequestResponseBodyMethodProcessorTests {
RequestResponseBodyMethodProcessor processor = new RequestResponseBodyMethodProcessor(converters);
assertThat(processor.supportsParameter(methodParameter)).isTrue();
String value = (String) processor.readWithMessageConverters(
this.request, methodParameter, methodParameter.getGenericParameterType());
assertThat(value).isEqualTo("foo");
}
@Test // gh-24127
public void resolveArgumentTypeVariableWithGenericInterfaceAndSubclass() throws Exception {
this.servletRequest.setContent("\"foo\"".getBytes("UTF-8"));
this.servletRequest.setContentType(MediaType.APPLICATION_JSON_VALUE);
Method method = SubControllerImplementingInterface.class.getMethod("handle", Object.class);
HandlerMethod handlerMethod = new HandlerMethod(new SubControllerImplementingInterface(), method);
MethodParameter methodParameter = handlerMethod.getMethodParameters()[0];
List<HttpMessageConverter<?>> converters = new ArrayList<>();
converters.add(new MappingJackson2HttpMessageConverter());
RequestResponseBodyMethodProcessor processor = new RequestResponseBodyMethodProcessor(converters);
assertThat(processor.supportsParameter(methodParameter)).isTrue();
String value = (String) processor.readWithMessageConverters(
this.request, methodParameter, methodParameter.getGenericParameterType());
assertThat(value).isEqualTo("foo");
@@ -1041,4 +1062,13 @@ public class RequestResponseBodyMethodProcessorTests {
static class MyControllerImplementingInterface implements MappingInterface<String> {
}
static class SubControllerImplementingInterface extends MyControllerImplementingInterface {
@Override
public String handle(String arg) {
return arg;
}
}
}