Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconstant behavior for name/value property of @RequestParam #664

Open
chrgue opened this issue Nov 3, 2017 · 3 comments
Open

Inconstant behavior for name/value property of @RequestParam #664

chrgue opened this issue Nov 3, 2017 · 3 comments

Comments

@chrgue
Copy link

chrgue commented Nov 3, 2017

According to the documentation for @RequestParam the value property acts as an alias for the name property.

Unfortunately there is an inconstant behavior when generating links by using the name property.

Here is my dummy controller:

@Controller
public class MyController {

    @GetMapping("/foo")
    public ResponseEntity<String> methodWithRequestParamNamedByValue(@RequestParam(value="age") int a){
        return null;
    }

    @GetMapping("/foo")
    public ResponseEntity<String> methodWithRequestParamNamedByName(@RequestParam(name="age") int a){
        return null;
    }
}

And here is the test to this controller:

public class MyControllerTest {

    @Before
    public void setUp() {
        ServletRequestAttributes requestAttributes = new ServletRequestAttributes(new MockHttpServletRequest());
        RequestContextHolder.setRequestAttributes(requestAttributes);
    }


    @Test
    public void methodWithRequestParamNamedByValue() throws Exception {
        Link link = linkTo(methodOn(MyController.class).methodWithRequestParamNamedByValue(1)).withSelfRel();
        assertThat(link.getHref(), is("http://localhost/foo?age=1"));
    }


    // FAILING with "http://localhost/foo?a=1"
    @Test
    public void methodWithRequestParamNamedByName() throws Exception {
        Link link = linkTo(methodOn(MyController.class).methodWithRequestParamNamedByName(1)).withSelfRel();
        assertThat(link.getHref(), is("http://localhost/foo?age=1"));
    }
}
@odrotbohm
Copy link
Member

Which version are you using, I think we fixed something in the alias detection in the recently released 0.24.

@chrgue
Copy link
Author

chrgue commented Nov 6, 2017

Hi @olivergierke,
we are using spring-boot 1.5.8.RELEASE's version of spring-hateoas, which is 0.23.0.RELEASE.

The bug is fixed in 0.24.RELEASE. Thanks for that.

We will waiting for the alignment with spring boot.

@chrgue
Copy link
Author

chrgue commented Feb 2, 2021

rather late than never :)

We're currently on spring-hateoas 1.1.3 and there is no problems with this issue.

Can be closed!

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants