EindbaasExpress / handsonscala-issuemigrator

Part of the HandsOnScala Course
0 stars 0 forks source link

read json throws NullPointerException with Scala3 #125

Open EindbaasExpress opened 2 years ago

EindbaasExpress commented 2 years ago

Reading json generated by write throws NullPointerException with Scala3, the same code with Scala2.13 runs without problems.

build.sbt

scalaVersion := "3.1.0" // 2.13.7 works correct, 3.1.0 crashes
libraryDependencies ++= Seq("com.lihaoyi" %% "upickle" % "1.4.2")

Code reproducing the problem

import upickle.default._

object ShowCrash {
  case class Node(name: String, kids: Vector[Node])

  implicit val nodeRW: ReadWriter[Node] = macroRW[Node]

  val ndb = Node("b", Vector.empty)
  val nda = Node("a", Vector(ndb))

  def main(args: Array[String]): Unit = {
    println(s"nda: $nda")
    val json = write(nda)
    println(s"json: $json")
    val node = read[Node](json)
    println(s"node: $node")
  }
}

Fails with:

nda: Node(a,Vector(Node(b,Vector())))
json: {"name":"a","kids":[{"name":"b","kids":[]}]}
[error] (run-main-1) java.lang.NullPointerException
[error] java.lang.NullPointerException
[error]         at ujson.CharParser.parseNested(CharParser.scala:401)

ID: 371 Original Author: otto-ringhofer