spray-Json java.lang.OutOfMemoryError 调用parseJson时

Spray-Json java.lang.OutOfMemoryError when calling parseJson

我正在使用 spray-json 1.3.0。我有一段简单的 Json 请求 spray 解析,这里是

import org.scalatest.{FlatSpec, MustMatchers}
import spray.json._

class BlockCypherOutputMarshallerTest extends FlatSpec with MustMatchers {

  val expectedOutput = """{"value":7454642,
                         |"script":"76a9148d5968ad26f9e277849ff9f8f39920f28944467388ac",
                         |"addresses":["mtQLgLiqmytKkgE9sVGwypAFsLvkxBQ6XX"],
                         |"script_type":"pay-to-pubkey-hash}""".stripMargin
  val json = expectedOutput.parseJson
  "BlockCypherOutputMarshaller" must "parse an output from the blockcypher api" in {
     //test case
  }
}

但是我在调​​用 val json = expectedOutput.parseJson 的行上收到一条错误消息。这是错误信息

> last test:testOnly
[debug] Running TaskDef(com.blockcypher.api.marshallers.BlockCypherOutputMarshallerTest, org.scalatest.tools.Framework$$anon@4178c07b, false, [SuiteSelector])
java.lang.OutOfMemoryError: Java heap space
    at java.util.Arrays.copyOf(Arrays.java:3332)
    at java.lang.AbstractStringBuilder.expandCapacity(AbstractStringBuilder.java:137)
    at java.lang.AbstractStringBuilder.ensureCapacityInternal(AbstractStringBuilder.java:121)
    at java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:622)
    at java.lang.StringBuilder.append(StringBuilder.java:202)
    at spray.json.JsonParser.appendSB(JsonParser.scala:179)
    at spray.json.JsonParser.char(JsonParser.scala:138)
    at spray.json.JsonParser.string(JsonParser.scala:129)
    at spray.json.JsonParser.value(JsonParser.scala:62)
    at spray.json.JsonParser.members(JsonParser.scala:80)
    at spray.json.JsonParser.object(JsonParser.scala:84)
    at spray.json.JsonParser.value(JsonParser.scala:59)
    at spray.json.JsonParser.parseJsValue(JsonParser.scala:43)
    at spray.json.JsonParser$.apply(JsonParser.scala:28)
    at spray.json.PimpedString.parseJson(package.scala:45)
    at com.blockcypher.api.marshallers.BlockCypherOutputMarshallerTest.<init>(BlockCypherOutputMarshallerTest.scala:16)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
    at java.lang.Class.newInstance(Class.java:442)
    at org.scalatest.tools.Framework$ScalaTestTask.execute(Framework.scala:641)
    at sbt.TestRunner.runTest(TestFramework.scala:76)
    at sbt.TestRunner.run(TestFramework.scala:85)
    at sbt.TestFramework$$anon$$anonfun$$init$$$anonfun$apply.apply(TestFramework.scala:202)
    at sbt.TestFramework$$anon$$anonfun$$init$$$anonfun$apply.apply(TestFramework.scala:202)
    at sbt.TestFramework$.sbt$TestFramework$$withContextLoader(TestFramework.scala:185)
    at sbt.TestFramework$$anon$$anonfun$$init$.apply(TestFramework.scala:202)
    at sbt.TestFramework$$anon$$anonfun$$init$.apply(TestFramework.scala:202)
    at sbt.TestFunction.apply(TestFramework.scala:207)
    at sbt.Tests$$anonfun.apply(Tests.scala:216)
    at sbt.Tests$$anonfun.apply(Tests.scala:216)
[error] Could not run test com.blockcypher.api.marshallers.BlockCypherOutputMarshallerTest: java.lang.OutOfMemoryError: Java heap space
[debug] Summary for ScalaCheck not available.
[debug] Summary for specs2 not available.
[info] ScalaTest
[info] Run completed in 1 second, 541 milliseconds.
[info] Total number of tests run: 0
[info] Suites: completed 0, aborted 0
[info] Tests: succeeded 0, failed 0, canceled 0, ignored 0, pending 0
[info] No tests were executed.
[error] Error: Total 0, Failed 0, Errors 0, Passed 0
[error] Error during tests:
[error]     com.blockcypher.api.marshallers.BlockCypherOutputMarshallerTest
[error] (test:testOnly) sbt.TestsFailedException: Tests unsuccessful

我不确定为什么我 运行 堆 space,看起来 json 的部分很简单而且我在任何方面都没有任何问题其他类似大小 json 的测试用例。

您需要在最后一行“pay-to-pubkey-hash”中结束引用

"script_type":"pay-to-pubkey-hash}"""

应该是

"script_type":"pay-to-pubkey-hash"}"""