Open amnaredo opened 3 years ago
I think I'm going to call this a wontfix; we can't really change this without changing the way parsers deal with singletons/companions, and even if we were willing to make the change it would mean appending a $
or similar to companion object's $type
tag which is pretty ugly in the common case.
A workaround for now could be to use the @upickle.implicits.key
annotation to specify a different $type
tag manually:
@ {
import upickle.default._
sealed trait Data
case class Data1(i: Int, s: String) extends Data
@upickle.implicits.key("Data1Companion")
case object Data1 extends Data
implicit val rw: ReadWriter[Data] = ReadWriter.merge(macroRW[Data1], macroRW[Data1.type])
read[Data](write[Data](Data1(1, "x"))) // res0: Data = Data1(1,x)
read[Data](write[Data](Data1))
}
import upickle.default._
defined trait Data
defined class Data1
defined object Data1
rw: ReadWriter[Data] = upickle.core.Types$TaggedReadWriter$Node@42401b81
res1_5: Data = Data1(1, "x")
res1_6: Data = Data1
Original Author: lihaoyi
The following compiles but fails at runtime:
Switching the order of the instances in merge returns incorrect result.
ID: 257 Original Author: ajaychandran