Search code examples
groovyrest-client

Groovy RestClient throws an Error when Getting the List of Object


Groovy RestClient throw the following Error when Getting the List of Object

this is the code

List<Code> codeList = restClient.get(path:"codes",headers: [Accept: 'application/json'])

Exception in thread "main" org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'groovyx.net.http.HttpResponseDecorator@7526515b' with class 'groovyx.net.http.HttpResponseDecorator' to class 'java.util.List'
        at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToType(DefaultTypeTransformation.java:360)
        at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.castToType(ScriptBytecodeAdapter.java:599)

Solution

  • After changing the code like below ,its working fine

    def codeList = restClient.get(path:"codes",headers: [Accept: 'application/json'])
    List<Code> codes = codeList.data