#617 - AnnotatedParametersParameterAccessor now considers @AliasFor declarations.
We're now using SynthesizingMethodParameter to correctly support annotation attributes that use @AliasFor. Original pull request: #621.
This commit is contained in:
committed by
Oliver Gierke
parent
4ad8c3b9aa
commit
5faf9858bb
@@ -24,6 +24,7 @@ import java.util.Map;
|
||||
import org.springframework.core.DefaultParameterNameDiscoverer;
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.core.ParameterNameDiscoverer;
|
||||
import org.springframework.core.annotation.SynthesizingMethodParameter;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ConcurrentReferenceHashMap;
|
||||
|
||||
@@ -151,7 +152,7 @@ public class MethodParameters {
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
private static class AnnotationNamingMethodParameter extends MethodParameter {
|
||||
private static class AnnotationNamingMethodParameter extends SynthesizingMethodParameter {
|
||||
|
||||
private final AnnotationAttribute attribute;
|
||||
private String name;
|
||||
|
||||
@@ -580,6 +580,16 @@ public class ControllerLinkBuilderUnitTest extends TestUtils {
|
||||
assertThat(link.getHref(), endsWith("?value=1"));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see #617
|
||||
*/
|
||||
@Test
|
||||
public void alternativePathVariableParameter() {
|
||||
|
||||
Link link = linkTo(methodOn(ControllerWithMethods.class).methodWithAlternatePathVariable("bar")).withSelfRel();
|
||||
assertThat(link.getHref(), is("http://localhost/something/bar/foo"));
|
||||
}
|
||||
|
||||
private static UriComponents toComponents(Link link) {
|
||||
return UriComponentsBuilder.fromUriString(link.expand().getHref()).build();
|
||||
}
|
||||
@@ -647,6 +657,11 @@ public class ControllerLinkBuilderUnitTest extends TestUtils {
|
||||
return null;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/{id}/foo")
|
||||
HttpEntity<Void> methodWithAlternatePathVariable(@PathVariable(name = "id") String otherId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/foo")
|
||||
HttpEntity<Void> methodForOptionalNextPage(@RequestParam(required = false) Integer offset) {
|
||||
return null;
|
||||
|
||||
@@ -15,7 +15,11 @@
|
||||
*/
|
||||
package org.springframework.hateoas.mvc;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.hamcrest.MatcherAssert.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.hateoas.Link;
|
||||
import org.springframework.hateoas.TestUtils;
|
||||
import org.springframework.hateoas.core.DummyInvocationUtils;
|
||||
import org.springframework.http.HttpEntity;
|
||||
@@ -30,10 +34,17 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
||||
public class DummyInvocationUtilsUnitTest extends TestUtils {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
public void pathVariableWithDefaultParameter() {
|
||||
|
||||
ControllerLinkBuilder.linkTo(DummyInvocationUtils.methodOn(SampleController.class).someMethod(1L));
|
||||
Link link = ControllerLinkBuilder.linkTo(DummyInvocationUtils.methodOn(SampleController.class).someMethod(1L)).withSelfRel();
|
||||
assertThat(link.getHref(), is("http://localhost/sample/1/foo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pathVariableWithNameParameter() {
|
||||
|
||||
Link link = ControllerLinkBuilder.linkTo(DummyInvocationUtils.methodOn(SampleController.class).someOtherMethod(2L)).withSelfRel();
|
||||
assertThat(link.getHref(), is("http://localhost/sample/2/bar"));
|
||||
}
|
||||
|
||||
@RequestMapping("/sample")
|
||||
@@ -43,5 +54,10 @@ public class DummyInvocationUtilsUnitTest extends TestUtils {
|
||||
HttpEntity<Void> someMethod(@PathVariable("id") Long id) {
|
||||
return new ResponseEntity<Void>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@RequestMapping("/{otherName}/bar")
|
||||
HttpEntity<Void> someOtherMethod(@PathVariable(name = "otherName") Long id) {
|
||||
return new ResponseEntity<Void>(HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user