Search code examples
scalamongodblift

How to store an Enumeration within a MongoCaseClassField in Lift Record?


Using Lift Record, when I try to retrieve the MongoDB entry below, a NullPointerException is raised when the .asHtml method of MongoCaseClassField is called.

object MyEnumeration extends Enumeration {
  val A, B, C = Value
}

case class MyCaseClass(en: MyEnumeration.Value) 

class MyRecord extends MongoRecord[MyRecord] with MongoId[MyRecord] {
  def meta = MyRecord
  object fail extends MongoCaseClassField[MyRecord, MyCaseClass](this)
}

object MyRecord extends MyRecord with MongoMetaRecord[MyRecord]

However this works fine if I use String instead of Enumeration. Is there any way to use enumerations in case class fields or should use a different type of field?


Solution

  • I am quite certain that this will only work with native types like String, Int, Float, Double, Boolean, etc, but not Enumerations. I am really certain that this is due to serialization.