Add reflection hints for data binding in Web controllers

Closes gh-28623
This commit is contained in:
Sébastien Deleuze
2022-07-11 11:37:41 +02:00
parent 4104ea7c1c
commit 9d42779826
2 changed files with 24 additions and 1 deletions

View File

@@ -74,6 +74,24 @@ public class RequestMappingReflectiveProcessorTests {
typeHint -> assertThat(typeHint.getType()).isEqualTo(TypeReference.of(String.class)));
}
@Test
void registerReflectiveHintsForMethodWithModelAttribute() throws NoSuchMethodException {
Method method = SampleController.class.getDeclaredMethod("postForm", Request.class);
processor.registerReflectionHints(hints, method);
assertThat(hints.typeHints()).satisfiesExactlyInAnyOrder(
typeHint -> assertThat(typeHint.getType()).isEqualTo(TypeReference.of(SampleController.class)),
typeHint -> {
assertThat(typeHint.getType()).isEqualTo(TypeReference.of(Request.class));
assertThat(typeHint.getMemberCategories()).containsExactlyInAnyOrder(
MemberCategory.INVOKE_DECLARED_CONSTRUCTORS,
MemberCategory.DECLARED_FIELDS);
assertThat(typeHint.methods()).satisfiesExactlyInAnyOrder(
hint -> assertThat(hint.getName()).isEqualTo("getMessage"),
hint -> assertThat(hint.getName()).isEqualTo("setMessage"));
},
typeHint -> assertThat(typeHint.getType()).isEqualTo(TypeReference.of(String.class)));
}
@Test
void registerReflectiveHintsForMethodWithRestController() throws NoSuchMethodException {
Method method = SampleRestController.class.getDeclaredMethod("get");
@@ -177,6 +195,10 @@ public class RequestMappingReflectiveProcessorTests {
void post(@RequestBody Request request) {
}
@PostMapping
void postForm(@ModelAttribute Request request) {
}
@GetMapping
@ResponseBody
String message() {