amnaredo / test

0 stars 0 forks source link

upickle.Invalid$Data: data: Str(sValue) msg: Array(n) #73

Open amnaredo opened 3 years ago

amnaredo commented 3 years ago

Hi!

With this code

package fun

import upickle._

object TestUpickle extends App {

  case class In(s: Option[String] = None)
  case class Out(in: In)

  def test1: Unit = {
    val str = """{"in": {"s": "sValue"}}"""
    println(read[Out](str))
  }

  test1
}

have got

Exception in thread "main" upickle.Invalid$Data: data: Str(sValue) msg: Array(n)
    at upickle.Implicits$$anonfun$validate$1.applyOrElse(Implicits.scala:16)
    at upickle.Implicits$$anonfun$validate$1.applyOrElse(Implicits.scala:16)
    at scala.runtime.AbstractPartialFunction.apply(AbstractPartialFunction.scala:36)
    at upickle.Implicits$$anonfun$upickle$Implicits$$SeqLikeR$1.applyOrElse(Implicits.scala:78)
    at upickle.Implicits$$anonfun$upickle$Implicits$$SeqLikeR$1.applyOrElse(Implicits.scala:78)
    at scala.PartialFunction$OrElse.apply(PartialFunction.scala:162)
    at upickle.Types$class.readJs(Types.scala:127)
    at upickle.package$.readJs(package.scala:10)
    at upickle.Generated$$anonfun$Tuple1R$1.applyOrElse(Generated.scala:17)
    at upickle.Generated$$anonfun$Tuple1R$1.applyOrElse(Generated.scala:17)
    at scala.PartialFunction$OrElse.apply(PartialFunction.scala:162)
    at upickle.Types$class.readJs(Types.scala:127)
    at upickle.package$.readJs(package.scala:10)
    at upickle.Generated$InternalGenerated$$anonfun$Case1R$1.applyOrElse(Generated.scala:197)
    at upickle.Generated$InternalGenerated$$anonfun$Case1R$1.applyOrElse(Generated.scala:197)
    at scala.runtime.AbstractPartialFunction.apply(AbstractPartialFunction.scala:36)
    at upickle.GeneratedUtil$$anonfun$readerCaseFunction$1.applyOrElse(GeneratedUtil.scala:15)
    at upickle.GeneratedUtil$$anonfun$readerCaseFunction$1.applyOrElse(GeneratedUtil.scala:15)
    at scala.PartialFunction$OrElse.apply(PartialFunction.scala:162)
    at upickle.Types$class.readJs(Types.scala:127)
    at upickle.package$.readJs(package.scala:10)
    at upickle.Generated$$anonfun$Tuple1R$1.applyOrElse(Generated.scala:17)
    at upickle.Generated$$anonfun$Tuple1R$1.applyOrElse(Generated.scala:17)
    at scala.PartialFunction$OrElse.apply(PartialFunction.scala:162)
    at upickle.Types$class.readJs(Types.scala:127)
    at upickle.package$.readJs(package.scala:10)
    at upickle.Generated$InternalGenerated$$anonfun$Case1R$1.applyOrElse(Generated.scala:197)
    at upickle.Generated$InternalGenerated$$anonfun$Case1R$1.applyOrElse(Generated.scala:197)
    at scala.runtime.AbstractPartialFunction.apply(AbstractPartialFunction.scala:36)
    at upickle.GeneratedUtil$$anonfun$readerCaseFunction$1.applyOrElse(GeneratedUtil.scala:15)
    at upickle.GeneratedUtil$$anonfun$readerCaseFunction$1.applyOrElse(GeneratedUtil.scala:15)
    at scala.PartialFunction$OrElse.apply(PartialFunction.scala:162)
    at upickle.Types$class.readJs(Types.scala:127)
    at upickle.package$.readJs(package.scala:10)
    at upickle.Types$class.read(Types.scala:123)
    at upickle.package$.read(package.scala:10)
    at fun.TestUpickle$.test1(TestUpickle.scala:12)
...

Where is my mistake?

ID: 15 Original Author: gaydenko

amnaredo commented 3 years ago

The tree seems to be as expected: Obj(ArrayBuffer((in,Obj(ArrayBuffer((s,Str(sValue)))))))

Original Author: gaydenko

amnaredo commented 3 years ago

Your mistake is that Option[String] is written as [] or ["..."]. We don't have unboxed strings in uPickle either, and I don't think it's possible to do so elegantly if we want to make https://github.com/lihaoyi/upickle/issues/12 work aswell

Original Author: lihaoyi

amnaredo commented 3 years ago

FWIW, the approach i would have taken to debugging this would be to instantiate a few of those things and write-ing/read-ing it, that'd probably have made this obvious when you looked at the stuff it spat out

Original Author: lihaoyi

amnaredo commented 3 years ago

Ouch! Very sudden view at Option. To my taste, of course. As for nulls, well, Scala (as well as you and me) hates them, doesn't it?

Original Author: gaydenko