1

我有一个枚举,我试图用酸洗 0.8.0 和 scala 2.11 来酸洗和解开:

object CommandType extends Enumeration {
  val Push, Pop = Value
}

酸洗目前无法自动完成。自定义pickler-unpickler 看起来像这样:

class CommandTypePickler(implicit val format: PickleFormat)
  extends SPickler[CommandType.Value] with Unpickler[CommandType.Value] with LazyLogging {

  def pickle(picklee: CommandType.Value, builder: PBuilder): Unit = {
    builder.beginEntry(picklee)
    builder.putField("commandType", b =>
      b.hintTag(stringTag).beginEntry(picklee.toString).endEntry()
    )
    builder.endEntry()
  }

  override def unpickle(tag: => FastTypeTag[_], reader: PReader): CommandType.Value = {
    val ctReader = reader.readField("commandType")
    val tag = ctReader.beginEntry()
    logger.debug(s"tag is ${tag.toString}")
    val value = stringUnpickler.unpickle(tag, ctReader).asInstanceOf[String]
    ctReader.endEntry()

    CommandType.withName(value)
  }
}

序列化枚举:

{
  "tpe": "scala.Enumeration.Value",
  "commandType": {
    "tpe": "java.lang.String",
    "value": "Push"
  }
}

当 unpickling 时,这会抛出以下内容:ScalaReflectionException: : class scala.Enumeration.Value in JavaMirror with sun.misc.Launcher$AppClassLoader@5c3eeab3 of type class sun.misc.Launcher$AppClassLoader with classpath ... not found. 我究竟做错了什么?

4

0 回答 0