Reputation: 3200
I would like to serialize/deserialize 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 which describes my Mongo datamodel and I can not just change serialization to custom implementation.
May be I can build some custom Transformer direct for Map[MyEnum.Value,Boolean] but how?
Upvotes: 1
Views: 232
Reputation: 10311
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?
Upvotes: 1