EindbaasExpress / handsonscala-issuemigrator

Part of the HandsOnScala Course
0 stars 0 forks source link

Default values not working with @key annotation in Scala 3 #99

Open EindbaasExpress opened 2 years ago

EindbaasExpress commented 2 years ago
case class Person(
                     @key("first_name") firstName: String = "N/A",
                     @key("last_name") lastName: String)
object Person {
    implicit val rw: RW[Person] = macroRW
}

val json = """{"last_name": "Snow"}"""
val p = read[Person](json)

This code fragment executes with exception:

Exception in thread "main" java.lang.ExceptionInInitializerError
    at com.nitka.rb.RBSyncApp.main(RBSyncApp.scala)
Caused by: upickle.core.AbortException: missing keys in dictionary: first_name at index 20
    at ujson.CharParser$$anon$1.applyOrElse(CharParser.scala:343)
    at ujson.CharParser$$anon$1.applyOrElse(CharParser.scala:341)
    at scala.runtime.AbstractPartialFunction.apply(AbstractPartialFunction.scala:35)
    at ujson.CharParser.liftedTree1$1(CharParser.scala:496)
    at ujson.CharParser.tryCloseCollection(CharParser.scala:496)
    at ujson.CharParser.parseNested(CharParser.scala:462)
    at ujson.CharParser.parseTopLevel0(CharParser.scala:323)
    at ujson.CharParser.parseTopLevel(CharParser.scala:307)
    at ujson.CharParser.parse(CharParser.scala:59)
    at ujson.StringParser$.transform(StringParser.scala:28)
    at ujson.StringParser$.transform(StringParser.scala:28)
    at ujson.Readable$fromTransformer.transform(Readable.scala:13)
    at upickle.Api.read$$anonfun$1(Api.scala:37)
    at upickle.core.TraceVisitor$.withTrace(TraceVisitor.scala:18)
    at upickle.Api.read(Api.scala:37)
    at upickle.Api.read$(Api.scala:17)
    at upickle.default$.read(Api.scala:133)
    at com.nitka.rb.RBSyncApp$.<clinit>(RBSyncApp.scala:76)
    ... 1 more
Caused by: upickle.core.Abort: missing keys in dictionary: first_name
    at com.nitka.rb.RBSyncApp$$anon$1.make(RBSyncApp.scala:72)
    at com.nitka.rb.RBSyncApp$$anon$1.make(RBSyncApp.scala:72)
    at upickle.implicits.CaseClassReaderPiece$$anon$1.visitEnd(CaseClassReader.scala:30)
    ... 16 more

Reproduced with uPickle version 1.4.0

ID: 360 Original Author: pharod