在scala 2.8和liftweb.net 2.0中,我试图将case类序列化为json,但当case类中包含枚举时,它会失败。
import net.liftweb.json.DefaultFormats
import net.liftweb.json.Extraction._
import net.liftweb.json.JsonDSL._
import net.liftweb.json.JsonAST.JObject
// Enumerated type
object ColorType extends scala.Enumeration {
type ColorType = Value
val Red, Blue, Grean = Value
}
然后是案例类-
case class colorInfo (name : String, color : ColorType)
试图转换为Jobject的代码
val tColor = colorInfo("sienna",ColorType.Blue)
implicit val formats = DefaultFormats
val x = decompose(tColor).asInstanceOf[JObject]
我得到这个错误:
java.lang.NoSuchFieldException: $outer
at java.lang.Class.getDeclaredField(Class.java:1882)
at net.liftweb.json.Extraction$$anonfun$decompose$6.apply(Extraction.scala:82)
at net.liftweb.json.Extraction$$anonfun$decompose$6.apply(Extraction.scala:81)
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:206)
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:206)
at scala.collection.LinearSeqOptimized$class.foreach(LinearSeqOptimized.scala:61)
at scala.collection.immutable.List.foreach(List.scala:45)
at scala.collection.TraversableLike$class.map(TraversableLike.scala:206)
at scala.collection.immutable.List.map(List.scala:45)
at net.liftweb.json.Extraction$.decompose(Extraction.scala:81)
at net.liftweb.json.Extraction$$anonfu...