Grails - Error in generating custom JSON in controller -


i trying create custom json output in controller using following code getting error "unexpected token <" in chrome rest client. same code works xml.

def customjson = {      def = student.list().get(0)      render(contenttype:"application/json"){          student(){ name(a.firstname) }     }  }  def customxml = {      def = student.list().get(0)      render(contenttype:"text/xml"){          student(){ name(a.firstname) }     }  } 

your code causes following exception:

message: array elements must defined "element" method call eg: element(value)     line | method ->>   98 | invokemethod      in grails.web.jsonbuilder 

the problem grails send html response content of exception 'application/json' content type. client thinks invalid json reponse.

the following code should work:

def = student.list().get(0)  render(contenttype:"application/json"){             student(name : a.firstname)         } 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -