Skip to content

read json throws NullPointerException with Scala3 #371

@otto-ringhofer

Description

@otto-ringhofer

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions