Using latest Spring-MVC (3.1.2.RELEASE)
I have a pagable REST method something like:
@RequestMapping(value = "/myThings", method = RequestMethod.GET)
public @ResponseBody
Page<MyThings> findMyThings(@Valid PageRequest pageRequest) {
Page<MyThings> myThings = myService.findMyThings(pageRequest);
return myThings;
}
Trying to test with org.springframework.web.client.RestOperations. Everything works okay, especially for non-pagable requests. However, with pagable ones, the ‘pageRequest’ object received in the REST method is one created by the default constructor and not the one created and passed into the call.
This is what I tried (where restTemplate is an instance of “RestOperations”:
.... // make the pageRequest object
if (pageRequest != null) {
params.put("pageRequest", pageRequest);
}
String json = restTemplate.getForObject(restEndpoint + "/myThings",
String.class, Collections.unmodifiableMap(params));
I know the problem/issue is on this side – if I deploy to Tomcat and pass the pageRequest params through the URL the paging on the server-side works perfectly. Additionally, I stepped down through the Spring code and it looks like if the pageRequest is put into the Model, it will be pulled out, otherwise one gets the default which is what I am getting.
Can anyone help?
thanks!
The parameter for getForObject where you are passing
Collections.unmodifiableMap(params)is actuallyObject... urlVariables, where the variables are placeholders for @PathVariable type declaration, so this will only work for declarations where you have@PathVariablesAn alternative is to have it the way you have it but have support for query parameters this way: