salat serialize Map[Enum,Boolean] type

230 Views Asked by At

Hi I would like to serialize/deserealise to DBObject some map with enumeration as key using salat.

object MyEnum extends Enumeration {
  val VAL_ONE, VAL_TWO = Value
}
case class CanBeStored(a:Enumeration.Value)

case class CanNotBeStored(a:Map[Enumeration.Value,Boolean])
// Produces exception[[ClassCastException: com.mongodb.BasicDBObject cannot be cast to scala.collection.immutable.Map]]

As I understood it is not possible using current version. https://groups.google.com/forum/#!topic/scala-salat/s3Q548NM8yc

But may be there exists some round way to do it ? The real problem is that I have a rather deep nested case class model wich describes my Mongo datamodel and i can not just change serialisation to custom implementation.

May be I can build some custom Transformer direct for Map[MyEnum.Value,Boolean] but how ?

1

There are 1 best solutions below

1
noahlz On

Yes, you can implement custom transformers that could convert the String keys stored in mongo to your enum objects.

See: How to customize serialization behavior without annotations in Salat?