amnaredo / test

0 stars 0 forks source link

Obtaining parse tree #103

Open amnaredo opened 3 years ago

amnaredo commented 3 years ago

The following fails with an expansion error:

upickle.read[Js.Arr](contents)

I came up with a quick workaround, but I'd prefer if the above line worked:

case class Tree(tree: Js.Arr)
implicit val treeReader = upickle.Reader[Tree] {
  case t: Js.Arr => Tree(t)
}

upickle.read[Tree](contents)

ID: 56 Original Author: tindzk

amnaredo commented 3 years ago

If you are wanting to read in Js.* blobs in particular, upickle.json readJs function should let you do that. or upickle.json.read/upickle.json.readJs.

Of course, if you want to parse it using upickle's default pickling, that's another matter. I haven't tested it, but I bet we could make it work

Original Author: lihaoyi

amnaredo commented 3 years ago

I should have been more clear. The input is a JSON string and I expect upickle.read[Js.Arr](json) to return the full parse tree as-is, i.e. no pickling implicits should be applied. The above works, but I have to declare a case class and an implicit.

Original Author: tindzk

amnaredo commented 3 years ago

Yeah and upickle.json.read does exactly that

Original Author: lihaoyi