recoInrelax
recoInrelax

Reputation: 707

grails rest render and return

Is there any way to to this:

def getChannelListJSON = {
        def results = Channel2.list()
        def t1 = System.currentTimeMillis()

                render(contentType:"text/json") {
                        canais = array {
                                for(b in results) {
                                    canal = {

                                        id= b.id                                        
                                        nome= b.channel_name
                                        sigla= b.channel_sigla
                                    }

                                }
                        }   
                }

        def t2 = System.currentTimeMillis()
        def tt = t2 - t1

                new Statistic(servico: Servicos.findByName('getChannelListJSON'), totalTime: tt, date: new Date()).save()

    }

but instead of using render, i need to use :

return object as XML

Because i need to turn this rest method compatible with http://code.google.com/p/grails-jaxrs/wiki/GettingStarted and i cannot ge it using render.

Upvotes: 0

Views: 495

Answers (2)

user1669712
user1669712

Reputation:

Try:

JSONWithPadding getChannelListJSON(@DefaultValue("callback") @QueryParam("callback") String callback) {
  GenericEntity genericEntity = new GenericEntity<Type>(var contains result, Type.class);
  return new JSONWithPadding(genericEntity, callback);
}

Upvotes: 0

Travis
Travis

Reputation: 336

You would need to change the content type to "text/xml"

http://grails.org/doc/2.0.x/ref/Controllers/render.html

Upvotes: 1

Related Questions