diff --git a/spring-web/src/main/java/org/springframework/web/bind/annotation/ControllerMappingReflectiveProcessor.java b/spring-web/src/main/java/org/springframework/web/bind/annotation/ControllerMappingReflectiveProcessor.java index fede437015..9dabab84e8 100644 --- a/spring-web/src/main/java/org/springframework/web/bind/annotation/ControllerMappingReflectiveProcessor.java +++ b/spring-web/src/main/java/org/springframework/web/bind/annotation/ControllerMappingReflectiveProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2023 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. @@ -79,7 +79,8 @@ class ControllerMappingReflectiveProcessor implements ReflectiveProcessor { protected void registerParameterTypeHints(ReflectionHints hints, MethodParameter methodParameter) { if (methodParameter.hasParameterAnnotation(RequestBody.class) || - methodParameter.hasParameterAnnotation(ModelAttribute.class)) { + methodParameter.hasParameterAnnotation(ModelAttribute.class) || + methodParameter.hasParameterAnnotation(RequestPart.class)) { this.bindingRegistrar.registerReflectionHints(hints, methodParameter.getGenericParameterType()); } else if (HttpEntity.class.isAssignableFrom(methodParameter.getParameterType())) { diff --git a/spring-web/src/test/java/org/springframework/web/bind/annotation/ControllerMappingReflectiveProcessorTests.java b/spring-web/src/test/java/org/springframework/web/bind/annotation/ControllerMappingReflectiveProcessorTests.java index 8f68f9bc0d..74cb13cb24 100644 --- a/spring-web/src/test/java/org/springframework/web/bind/annotation/ControllerMappingReflectiveProcessorTests.java +++ b/spring-web/src/test/java/org/springframework/web/bind/annotation/ControllerMappingReflectiveProcessorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2023 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. @@ -183,6 +183,24 @@ public class ControllerMappingReflectiveProcessorTests { typeHint -> assertThat(typeHint.getType()).isEqualTo(TypeReference.of(SampleController.class))); } + @Test + void registerReflectiveHintsForMethodWithPartToConvert() throws NoSuchMethodException { + Method method = SampleController.class.getDeclaredMethod("postPartToConvert", 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))); + } + static class SampleController { @GetMapping @@ -225,6 +243,10 @@ public class ControllerMappingReflectiveProcessorTests { void postRawHttpEntity(HttpEntity entity) { } + @PostMapping + void postPartToConvert(@RequestPart Request request) { + } + } @RestController