1

我想在 Groovy 中解析 Json,但是它抛出异常,不知道我的代码有什么问题,需要一些帮助

[环境:]

jdk-9.0.4

想法:想法

语言: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'
}
4

1 回答 1

1

当 Java 9 出现时,这是旧版本 groovy 的一个错误

https://issues.apache.org/jira/plugins/servlet/mobile#issue/GROOVY-7716

更新 groovy 依赖项将修复它

于 2019-04-13T12:37:33.960 回答