Open amnaredo opened 3 years ago
This is probably caused by continuous compilation, in which there is a cache incongruity between macro-generated code and updated user code. sbt clean
and recompilation solved above issue so far.
But there's another scenario that can't be solved by clean
, described blow:
Original Author: cuzfrog
import upickle.default._
sealed trait Message{
def err:Seq[String]
}
object Message{
def fromJSON(in:String):Message = read[Message](in)
private implicit val readWriter: ReadWriter[Message] =
macroRW[PhoneMessage] merge macroRW[PcMessage]
}
case class PhoneMessage(phone:String,err:Seq[String] = Seq())
extends Message{
def toJSON:String = write(this)
}
case class PcMessage(pc:String,err:Seq[String] = Seq())
extends Message{
def toJSON:String = write(this)
}
val msg = PcMessage("iMac").toJSON
println(Message.fromJSON(msg))
I tested above, which works fine on jvm. But "Key Missing" occurs when using remotely. Original Author: cuzfrog
@cuzfrog can you elaborate what you mean with "when using remotely"?
I just ran into the same problem I think. when I test the reading/writing in the sbt console it works fine. but when it runs on the jvm it fails with the "key missing" message, even though the default parameters are specified. Original Author: torstenrudolf
in my case it didn't work when having a companion object next to the case class. after I renamed the object to something else it worked. -.- I had the same behaviour previously with a problem with a sealed trait hierarchy. but in the light of #209 it is probably unfortunately time to switch to a different lib ;/ Original Author: torstenrudolf
@torstenrudolf
what you mean with "when using remotely"?
js to jvm.
I reckon this problem arises when one of the conditions meets:
uPickle
's deficiency.Solutions:
read
or write
class hierarchy in top class:sealed trait Message{
def err:Seq[String]
def toJSON: String = write(this) //serialize this here.
}
object Message{
def fromJSON(in:String):Message = read[Message](in)
implicit val readWriter: ReadWriter[Message] =
macroRW[PhoneMessage] merge macroRW[PcMessage] // when implicit val is public, it can be seen from trait.
}
I think i didn't see the problem anymore when applied these solutions/principles. Original Author: cuzfrog
my problem persisted after sbt clean
in my case it failed with a very simple case class with no hierarchy:
case class X(a: Option[String] = None, b: Option[String] = None)
object X {
def something...
}
When reading in "{}" it would fail with key missing error (even after full compilation). but after I changed the object's name it worked. Original Author: torstenrudolf
Bug bankruptcy Original Author: lihaoyi
This is a serious bug:
case class definition:
test:
result:
While, on the server,
read
complains cannot findid
ID: 203 Original Author: cuzfrog