4
votes

There are ton of this question, and none of them has answer... When I call this method, the error popup in my console and the return is success. Whats the reason to cause this?

Using grails 3.1.8

Ambiguous method overloading for method grails.artefact.controller.support.ResponseRenderer$Trait$Helper#render.

Cannot resolve which method to invoke for [class com.union.KardexEntradaController, null] due to overlapping prototypes between: [interface grails.artefact.controller.support.ResponseRenderer, interface java.lang.CharSequence] [interface grails.artefact.controller.support.ResponseRenderer, interface java.util.Map] [interface grails.artefact.controller.support.ResponseRenderer, interface org.grails.web.converters.Converter]

def getKardexs(){
    def kardexs = Kardex.createCriteria().list{
        filial{
            eq('id', params.long('filial'))
        }
        produto {
            eq('categoriaKardex', CategoriaKardex.get(params.long('categoriaKardex')))
            eq('ativo', true)
            order('nome', 'asc')
        }
    }.collect{
        [id: it.id, nome: it.produto.nome]
    }

    render ((kardexs ? kardexs : null) as JSON)
}
3

3 Answers

2
votes

I had a same experience, you cannot render null, even with type casting, you should -as mentioned- use an empty Map, something like: this

render ((kardexs ? kardexs : [:]) as JSON)

Another important note, you should rename the action getKardexs() to something different because this is considered a getter property to kardexs which is defined just above (or rename kardexs to listKardexs or something else), this might cause another Exception.

2
votes

Grails render can't render NULL values. That's why its throwing Ambiguous method overloading error because it doesn't know which method to call.Render something else instead on null(may be some error message).

1
votes

I think it's because if kardexs is null then you're passing null into the ResponseRender render method & there are 3 to choose from that take a single parameter, one takes a Map, another a CharSequence and another a Converter, you're being warned about this, i.e. it's ambiguous which one you're calling.