2

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(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...