-
Notifications
You must be signed in to change notification settings - Fork 106
SupportedTypes
Salat provides built-in support for serializing and deserializing:
- case classes
- embedded case classes
- embedded case classes typed to a trait or abstract superclass annotated with
@Salat
- see traits and abstract superclasses with Salat for details. - Scala enums
- Options
- collections
Any supported type except collections are also supported as an Option
.
- Did you try using a default argument?
- Is it a
List
? UseNil
. - For anything else, use an empty instance of the collection -
Seq.empty
,Map.empty
, etc.
- Is it a
- Stop denormalizing the relationship into your model object. Instead, create a projection on a parent-child relationship.
- Are you contorting your model to compensate for a JSON library which doesn't support default arguments? Try using Salat's JSON support instead.
See collection support for a complete list of supported collection types.
Arrays are not currently supported.
Maps are represented as DBObject
; all other collections turn into DBList
.
Salat delegates serialization for most common types to Casbah's BSON support:
- String
- Boolean
- Int
- Double
- Long
- ObjectID
- Date
- UUID
Make sure that Casbah's BSON encoding hooks are in scope:
com.mongodb.casbah.commons.conversions.scala.RegisterConversionHelpers()
org.joda.time.DateTime
support requires registering Casbah's DateTime encoding hook in addition to Casbah's other conversion helpers:
com.mongodb.casbah.commons.conversions.scala.RegisterJodaTimeConversionHelpers()
Salat provides support for converting the following types to something BSON serializes natively:
-
Char
is serialized asString
-
Float
is serialized asDouble
-
BigDecimal
is serialized asDouble
- precision and rounding mode are preserved - see the section on BigDecimal handling in custom Salat contexts for details.
-
BigInt
is serialized asLong
You can support other types by creating custom BSON hooks.
Refer to com.mongodb.casbah.commons.conversions.scala.JodaDateTimeHelpers
to get started.
- Nested inner classes (as used in Cake pattern)
- A class typed at the top-level to a trait or an abstract superclass
com.mongodb.DBRef
- Any type of Map whose key is not a String
- any type of map whose key is a String containing
.
or$
- any type of map whose key is a String containing
- Either
- type aliases
- varargs
Salat tries to provide the benefit of the doubt by passing things it doesn't understand down to Casbah.
This means that your object can be serialized but you will encounter an exception from Salat when you try to deserialize. This is actually good news because the Salat exception should give you everything you need to post on the mailing list and get the problem fixed.
First, update to the latest snapshot of salat-core
and try again.
If that doesn't fix the problem, post to the mailing list.