In Scala 2.8 and liftweb.net 2.0 I'm trying to serialize a case-class to Json but when the case class has an enumeration in it it fails.
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 }
Then the case class -
case class colorInfo (name : String, color : ColorType)
Code that tries to convert to JObject
val tColor = colorInfo("sienna",ColorType.Blue) implicit val formats = DefaultFormats val x = decompose(tColor).asInstanceOf[JObject]
I get this error:
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开发者_Python百科(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...
There's no out-of-the-box support for scala.Enumeration yet. Please see this mailing list thread which outlines an extension adding Enumeration support for JSON:
http://groups.google.fi/group/liftweb/browse_thread/thread/d38090d804d902a3/7d7b55c4a63b2580?lnk=gst&q=json#7d7b55c4a63b2580
精彩评论