Reputation: 9296
I'm trying to build a restful api with grails. Now for resource listing I got a weird response:
{
"empty": false,
"totalCount": 229
}
But if I try to show a specific resource i.e /resource/1 I got expected response. What is going wrong with this?
Upvotes: 1
Views: 282
Reputation: 2686
It seems indeed that the origin of the problem is related to the version of Grails. I do not know if you found a solution in the meanwhile, but I just stumbled upon this problem and found this bug report: https://jira.grails.org/browse/GRAILS-11892
A workaround consists in appending toArray()
to all lists of objects. If you are using RestfulController
an example for the index
method (supposing you want to return a list of objects) could be:
class BookController extends RestfulController {
static responseFormats = ['json', 'xml']
BookController() {
super(Book)
}
@Override
def index(Integer max) {
params.max = Math.min(max ?: 10, 100)
respond listAllResources(params).toArray(), formats: ['json', 'xml']
}
}
This will give you the expected result rather than the ou7tput you cite in your question.
Upvotes: 1