Groovy RestClient 在获取对象列表时抛出错误
Groovy RestClient throws an Error when Getting the List of Object
Groovy RestClient 在获取对象列表时抛出以下错误
这是代码
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)
像下面这样更改代码后,它工作正常
def codeList = restClient.get(path:"codes",headers: [Accept: 'application/json'])
List<Code> codes = codeList.data
Groovy RestClient 在获取对象列表时抛出以下错误
这是代码
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)
像下面这样更改代码后,它工作正常
def codeList = restClient.get(path:"codes",headers: [Accept: 'application/json'])
List<Code> codes = codeList.data