1

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 ?

Oleg
  • 3,080
  • 3
  • 40
  • 51

1 Answers1

1

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?

Community
  • 1
  • 1
noahlz
  • 10,202
  • 7
  • 56
  • 75
  • Thanks, I have decided to implement my own salat like library but on macros: https://github.com/martende/mondao – Oleg Sep 13 '16 at 07:20