美文网首页JanusGraph
Gremlin---导入json数据出现Illegal unqu

Gremlin---导入json数据出现Illegal unqu

作者: zlcook | 来源:发表于2017-11-29 15:43 被阅读36次
    org.apache.tinkerpop.shaded.jackson.core.JsonParseException: Illegal unquoted character ((CTRL-CHAR, code 28)): has to be escaped using backslash to be included in string value
     at [Source: java.io.ByteArrayInputStream@60856961; line: 1, column: 381]
    java.lang.RuntimeException: org.apache.tinkerpop.shaded.jackson.core.JsonParseException: Illegal unquoted character ((CTRL-CHAR, code 28)): has to be escaped using backslash to be included in string value
     at [Source: java.io.ByteArrayInputStream@60856961; line: 1, column: 381]
            at org.apache.tinkerpop.gremlin.util.function.FunctionUtils.lambda$wrapFunction$0(FunctionUtils.java:40)
            at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
            at java.util.Iterator.forEachRemaining(Iterator.java:116)
            at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801)
            at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
            at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
            at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:151)
            at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:174)
            at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
            at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:418)
            at org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONReader.readGraph(GraphSONReader.java:104)
            at org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONIo.readGraph(GraphSONIo.java:96)
            at com.jd.jr.graph.data.JsonVerifyTest$$anonfun$1.apply$mcV$sp(JsonVerifyTest.scala:18)
            at com.jd.jr.graph.data.JsonVerifyTest$$anonfun$1.apply(JsonVerifyTest.scala:16)
            at com.jd.jr.graph.data.JsonVerifyTest$$anonfun$1.apply(JsonVerifyTest.scala:16)
            at org.scalatest.OutcomeOf$class.outcomeOf(OutcomeOf.scala:85)
            at org.scalatest.OutcomeOf$.outcomeOf(OutcomeOf.scala:104)
            at org.scalatest.Transformer.apply(Transformer.scala:22)
            at org.scalatest.Transformer.apply(Transformer.scala:20)
            at org.scalatest.FlatSpecLike$$anon$1.apply(FlatSpecLike.scala:1682)
            at org.scalatest.TestSuite$class.withFixture(TestSuite.scala:196)
            at org.scalatest.FlatSpec.withFixture(FlatSpec.scala:1685)
            at org.scalatest.FlatSpecLike$class.invokeWithFixture$1(FlatSpecLike.scala:1679)
            at org.scalatest.FlatSpecLike$$anonfun$runTest$1.apply(FlatSpecLike.scala:1692)
            at org.scalatest.FlatSpecLike$$anonfun$runTest$1.apply(FlatSpecLike.scala:1692)
            at org.scalatest.SuperEngine.runTestImpl(Engine.scala:289)
            at org.scalatest.FlatSpecLike$class.runTest(FlatSpecLike.scala:1692)
            at org.scalatest.FlatSpec.runTest(FlatSpec.scala:1685)
            at org.scalatest.FlatSpecLike$$anonfun$runTests$1.apply(FlatSpecLike.scala:1750)
            at org.scalatest.FlatSpecLike$$anonfun$runTests$1.apply(FlatSpecLike.scala:1750)
            at org.scalatest.SuperEngine$$anonfun$traverseSubNodes$1$1.apply(Engine.scala:396)
            at org.scalatest.SuperEngine$$anonfun$traverseSubNodes$1$1.apply(Engine.scala:384)
            at scala.collection.immutable.List.foreach(List.scala:392)
            at org.scalatest.SuperEngine.traverseSubNodes$1(Engine.scala:384)
            at org.scalatest.SuperEngine.org$scalatest$SuperEngine$$runTestsInBranch(Engine.scala:373)
            at org.scalatest.SuperEngine$$anonfun$traverseSubNodes$1$1.apply(Engine.scala:410)
            at org.scalatest.SuperEngine$$anonfun$traverseSubNodes$1$1.apply(Engine.scala:384)
            at scala.collection.immutable.List.foreach(List.scala:392)
            at org.scalatest.SuperEngine.traverseSubNodes$1(Engine.scala:384)
            at org.scalatest.SuperEngine.org$scalatest$SuperEngine$$runTestsInBranch(Engine.scala:379)
            at org.scalatest.SuperEngine.runTestsImpl(Engine.scala:461)
            at org.scalatest.FlatSpecLike$class.runTests(FlatSpecLike.scala:1750)
            at org.scalatest.FlatSpec.runTests(FlatSpec.scala:1685)
            at org.scalatest.Suite$class.run(Suite.scala:1147)
            at org.scalatest.FlatSpec.org$scalatest$FlatSpecLike$$super$run(FlatSpec.scala:1685)
            at org.scalatest.FlatSpecLike$$anonfun$run$1.apply(FlatSpecLike.scala:1795)
            at org.scalatest.FlatSpecLike$$anonfun$run$1.apply(FlatSpecLike.scala:1795)
            at org.scalatest.SuperEngine.runImpl(Engine.scala:521)
            at org.scalatest.FlatSpecLike$class.run(FlatSpecLike.scala:1795)
            at org.scalatest.FlatSpec.run(FlatSpec.scala:1685)
            at org.scalatest.tools.SuiteRunner.run(SuiteRunner.scala:45)
            at org.scalatest.tools.Runner$$anonfun$doRunRunRunDaDoRunRun$1.apply(Runner.scala:1340)
            at org.scalatest.tools.Runner$$anonfun$doRunRunRunDaDoRunRun$1.apply(Runner.scala:1334)
            at scala.collection.immutable.List.foreach(List.scala:392)
            at org.scalatest.tools.Runner$.doRunRunRunDaDoRunRun(Runner.scala:1334)
            at org.scalatest.tools.Runner$$anonfun$runOptionallyWithPassFailReporter$2.apply(Runner.scala:1011)
            at org.scalatest.tools.Runner$$anonfun$runOptionallyWithPassFailReporter$2.apply(Runner.scala:1010)
            at org.scalatest.tools.Runner$.withClassLoaderAndDispatchReporter(Runner.scala:1500)
            at org.scalatest.tools.Runner$.runOptionallyWithPassFailReporter(Runner.scala:1010)
            at org.scalatest.tools.Runner$.run(Runner.scala:850)
            at org.scalatest.tools.Runner.run(Runner.scala)
            at org.jetbrains.plugins.scala.testingSupport.scalaTest.ScalaTestRunner.runScalaTest2(ScalaTestRunner.java:138)
            at org.jetbrains.plugins.scala.testingSupport.scalaTest.ScalaTestRunner.main(ScalaTestRunner.java:28)
    Caused by: org.apache.tinkerpop.shaded.jackson.core.JsonParseException: Illegal unquoted character ((CTRL-CHAR, code 28)): has to be escaped using backslash to be included in string value
     at [Source: java.io.ByteArrayInputStream@60856961; line: 1, column: 381]
            at org.apache.tinkerpop.shaded.jackson.core.JsonParser._constructError(JsonParser.java:1702)
            at org.apache.tinkerpop.shaded.jackson.core.base.ParserMinimalBase._reportError(ParserMinimalBase.java:558)
            at org.apache.tinkerpop.shaded.jackson.core.base.ParserMinimalBase._throwUnquotedSpace(ParserMinimalBase.java:522)
            at org.apache.tinkerpop.shaded.jackson.core.json.UTF8StreamJsonParser._finishString2(UTF8StreamJsonParser.java:2540)
            at org.apache.tinkerpop.shaded.jackson.core.json.UTF8StreamJsonParser._finishAndReturnString(UTF8StreamJsonParser.java:2469)
            at org.apache.tinkerpop.shaded.jackson.core.json.UTF8StreamJsonParser.getText(UTF8StreamJsonParser.java:315)
            at org.apache.tinkerpop.shaded.jackson.databind.deser.std.UntypedObjectDeserializer$Vanilla.deserialize(UntypedObjectDeserializer.java:513)
            at org.apache.tinkerpop.shaded.jackson.databind.deser.std.UntypedObjectDeserializer$Vanilla.mapObject(UntypedObjectDeserializer.java:637)
            at org.apache.tinkerpop.shaded.jackson.databind.deser.std.UntypedObjectDeserializer$Vanilla.deserialize(UntypedObjectDeserializer.java:495)
            at org.apache.tinkerpop.shaded.jackson.databind.deser.std.UntypedObjectDeserializer$Vanilla.mapArray(UntypedObjectDeserializer.java:586)
            at org.apache.tinkerpop.shaded.jackson.databind.deser.std.UntypedObjectDeserializer$Vanilla.deserialize(UntypedObjectDeserializer.java:509)
            at org.apache.tinkerpop.shaded.jackson.databind.deser.std.UntypedObjectDeserializer$Vanilla.mapObject(UntypedObjectDeserializer.java:652)
            at org.apache.tinkerpop.shaded.jackson.databind.deser.std.UntypedObjectDeserializer$Vanilla.deserialize(UntypedObjectDeserializer.java:495)
            at org.apache.tinkerpop.shaded.jackson.databind.deser.std.MapDeserializer._readAndBindStringKeyMap(MapDeserializer.java:517)
            at org.apache.tinkerpop.shaded.jackson.databind.deser.std.MapDeserializer.deserialize(MapDeserializer.java:362)
            at org.apache.tinkerpop.shaded.jackson.databind.deser.std.MapDeserializer.deserialize(MapDeserializer.java:27)
            at org.apache.tinkerpop.shaded.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:3798)
            at org.apache.tinkerpop.shaded.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2915)
            at org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONReader.readVertex(GraphSONReader.java:176)
            at org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONReader.lambda$readGraph$0(GraphSONReader.java:104)
            at org.apache.tinkerpop.gremlin.util.function.FunctionUtils.lambda$wrapFunction$0(FunctionUtils.java:36)
            ... 62 more
    
    
    • 原因是导入json中存在Ascii码值为32(十进制)以下的控制字符,如换行、文件分隔符等,需要将其替换掉。

    • 如下存在文件控制符FS,其是不可见字符,但是有些软件打开时因为其使用的编码原因会显示成一些奇怪字符。文件控制符Ascill的10进制值为28,16进制值为1C


      image.png
    • 解决: 通过正则表达式将json中的控制符(ascill编码低于32的zif)替换掉

    val inputJsonData ="graph_importer/src/test/resources/proddata.json"
     val outJsonData ="graph_importer/src/test/resources/outData.json"
    
         "Content" should "  valid" in{
    
       val invalidCharReg ="""[\u0000-\u001F]+"""
       val source = Source.fromFile(inputJsonData,"UTF-8");
       val lineIterator = source.getLines();
       val out = new PrintWriter(outJsonData)
    
       for( line <- lineIterator ){
         var old = line.mkString
         old = old.replaceAll(invalidCharReg,"")
         out.println(old)
       }
       out.close()
     }
    

    相关文章

      网友评论

        本文标题:Gremlin---导入json数据出现Illegal unqu

        本文链接:https://www.haomeiwen.com/subject/lpzubxtx.html