1

I am currently migrating my application from grails 2.4.4 to grails 3.1.5 with the grails security Plugin.

i am using the grails ajax request plugin to make the ajax calls but getting this error after calling ajax.

I am returning an ArrayList of POJO and not POGO objects gotten from an API call

state/stateforcountry - parameters:
countryName: Ghana
Stacktrace follows:
java.lang.reflect.InvocationTargetException: null
        at grails.plugin.springsecurity.web.filter.GrailsAnonymousAuthenticationFilter.doFilter(GrailsAnonymousAuthenticationFilter.groovy:53)
        at grails.plugin.springsecurity.web.authentication.logout.MutableLogoutFilter.doFilter(MutableLogoutFilter.groovy:62)
        at grails.plugin.springsecurity.web.SecurityRequestHolderFilter.doFilter(SecurityRequestHolderFilter.groovy:58)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NullPointerException: null
        at grails.converters.JSON.value(JSON.java:180)
        at grails.converters.JSON.convertAnother(JSON.java:144)
        at grails.converters.JSON.value(JSON.java:184)
        at grails.converters.JSON.render(JSON.java:119)
        at grails.converters.JSON.render(JSON.java:132)
        at grails.artefact.controller.support.ResponseRenderer$Trait$Helper.render(ResponseRenderer.groovy:191)
        at smartinsure.admin.StateController$_stateForCountry_closure1$_closure2.doCall(StateController.groovy:29)
        at grails.artefact.Controller$Trait$Helper.withFormat(Controller.groovy:92)
        at smartinsure.admin.StateController.stateForCountry(StateController.groovy:28)
        ... 6 common frames omitted

Can anyone help out?

JohnTheBeloved
  • 2,323
  • 3
  • 19
  • 24

1 Answers1

1

I finally solved it by using another groovy conversion API from the groovy.json Package

def getUsers(){
   def users = userService.getAllUsers();
   render JsonOutput.toJson(users);
}

as opposed to this render users as JSON. JsonOutput is in the groovy.json package or better still

withFormat {
      html { render view:"edit", model:users}
      json { render JsonOutput.toJson(users)}
      xml { render users as XML}
}
JohnTheBeloved
  • 2,323
  • 3
  • 19
  • 24