Reputation: 2019
I am using grails-5.2.5 to migrate an application from grails-2.5.2 version. In grails-2 version there is a class RestVehicleTrackingController which extends RestfulController. The purpose of the class is to return Map object as JSON. No related domain is specified. But in grails-5 version I can see that a domain should be specified. But I need to query any domain and prepare Map then response as JSON which was happening in previous version. Isn't it possible to keep the code as it is? My attempts are as below:
"/api/vehicleList/$gatepassNo?(.$format)?"(controller: 'restVehicleTracking', action: 'getVehicleList')
class RestVehicleTrackingController extends RestfulController {
static allowedMethods = [search: 'GET', getVehicleList: 'GET']
def restCommonService
def vehicleTrackingService
def getVehicleList(String gatepassNo) {
def ipAddress = restCommonService.getClientIpAddress(request)
def url = '/api/ws/vt/gatePass/vehicleList'
String requestParams = params.toString()
if (gatepassNo) {
def retVal = vehicleTrackingService.getVehicleInformation(gatepassNo)
if (retVal) {
restCommonService.storeRequestInformation(url, requestParams, retVal.toString(), true, ipAddress, 'DOWN',)
respond retVal, formats: ['json', 'xml']
}
}
restCommonService.storeRequestInformation(url, requestParams, null, false, ipAddress, 'DOWN',)
respond null, status: 404
}
}
In grails-2.5.2 above code works fine and no error at extension. But in grails-5.2.5 this class RestVehicleTrackingController extends RestfulController
gives the following error:
There is no default constructor available in class 'grails.rest.RestfulController'
Upvotes: 0
Views: 46
Reputation: 996
I believe the above code is wrong and the error is expected. You should define a default constructor. For example:
class BookController extends RestfulController<Book> {
static responseFormats = ['json', 'xml']
BookController() {
super(Book)
}
}
So, you would need to do something similar with your example. Here is the link to the Grails framework documentation on Extending Restful Controller.
Upvotes: 0