I have method on server side:
@RequestMapping(method = RequestMethod.GET)
public List<UserDTO> getAllUsers(@RequestParam(value = "groupId", required = false) Long groupId,
@RequestParam(value = "pagination") Pagination pagination){
// some stuff
}
And I try to send data from client side with Restangular
:
function getUsers(filters){
restService.all("users").getList(filters).then(function(users){
$scope.data.users = users;
});
}
// ....
getUsers({groupId: undefined, pagination: $scope.data.pagination});
Where pagination
can be:
$scope.data = {
// Other parameters
pagination: {
currentPage: 1,
totalItems: 30,
itemsPerPage: 5
}
};
But I got:
Failed to convert value of type 'java.lang.String'
to required type 'pagination.Pagination';
When I looked for Request URL
I saw:
http://localhost:8080/skp/users?pagination=%7B%22currentPage%22:1,%22totalItems%22:30,%22itemsPerPage%22:5%7D
And Query String Parameters
were:
pagination:{"currentPage":1,"totalItems":30,"itemsPerPage":5}
Which I hope should send pagination object to server side, but it tries to send string not object. Is there any idea how, with HTTP GET
method and getList
Restangular
method send parameters not as Query String
, which I think causes my problem? Or how make server side to treat it as Pagination
object, not strings? Thank you very much for answers
pagination=%7B%22currentPage%22:1,%22totalItems%22:30,%22itemsPerPage%22:5%7D
As stated in my comment this is one parameter with value as string. If you want an object or input bean to be populated at server side, you have to send three values inside pagination as three separate parameters. Keeping parameter and bean field names same to auto puplulate these fields