我想在Groovy中解析Json,但是它引发了异常,不知道我的代码出了什么问题,需要一些帮助
[ENV:]
jdk-9.0.4
ide:idea
lang:Groovy
异常如下: 警告:发生了非法的反射访问操作 警告:org.codehaus.groovy.reflection.CachedClass $ 3 $ 1的非法反射访问(文件:/ C:/Users/hhbst/.gradle/caches/modules-2/files-2.1/org.codehaus.groovy/groovy-all /2.3.11/f6b34997d04c1538ce451d3955298f46fdb4dbd4/groovy-all-2.3.11.jar)转换为方法java.lang.Object.finalize() 警告:请考虑将此报告给org.codehaus.groovy.reflection.CachedClass $ 3 $ 1的维护者 警告:使用--illegal-access = warn启用有关进一步非法反射访问操作的警告 警告:在将来的版本中,所有非法访问操作都将被拒绝
java.lang.ClassCastException:[B不能强制转换为[C
at groovy.json.internal.FastStringUtils$StringImplementation$1.toCharArray(FastStringUtils.java:88)
at groovy.json.internal.FastStringUtils.toCharArray(FastStringUtils.java:175)
at groovy.json.internal.BaseJsonParser.parse(BaseJsonParser.java:103)
at groovy.json.JsonSlurper.parseText(JsonSlurper.java:208)
at groovy.json.JsonSlurper$parseText.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
at com.hypers.test.apitest.util.JsonUtilTest.JsonParaTest(JsonUtilTest.groovy:20)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
以退出代码-1完成的过程
@Test
void JsonParaTest(){
def jsonSlurper = new JsonSlurper()
def object = jsonSlurper.parseText('{ "name": "John Doe" }')
assert object.name == 'John Doe'
}
答案 0 :(得分:1)
这是Java 9发行时旧版本的groovy的错误
https://issues.apache.org/jira/plugins/servlet/mobile#issue/GROOVY-7716
更新groovy依赖关系将对其进行修复