Re: [salat] Serializing/Deserializing custom types wrapped in Option?

76 views
Skip to first unread message

rose katherine toomey

unread,
Mar 14, 2013, 10:29:25 AM3/14/13
to scala-salat
Sorry, Yusuke, looks like a bug.  I will investigate after work today.


On 14 March 2013 06:01, Yusuke KUOKA <yku...@gmail.com> wrote:
Hi,

I have a problem trying to serialize/deserialize custom types wrapped in Option.
The problemn is that `asDBObject` or `asObject` itself runs but doesn't seem to use my custom transformer.

I'm currently using Scala 2.9.1 with the Salat 1.9.2-SNAPSHOT.

And my custom types:

```
package example

case class Foo(value: String)
```

And my serializing/deserializing code and results:

```
import example.{Foo, Doc1, Doc2}
import com.novus.salat.{Context, grater}
import com.mongodb.casbah.Imports._
import com.novus.salat.transformers.CustomTransformer

val fooTransformer = new CustomTransformer[Foo, String] {
  def deserialize(b: String): Foo = Foo(b)
  def serialize(a: Foo): String = a.value
}

implicit val context = new Context {
  val name: String = "foo"
  registerCustomTransformer(
    fooTransformer
  )
}


/** Not O.K. The custom transformer is NOT USED for `foo` */
val doc2Grater = grater[Doc2]

doc2Grater.asDBObject(Doc2(Some(Foo("value"))))
//=> {"foo": {"value": "value"} }, but expected {"foo": "value"}

doc2Grater.asObject(DBObject("foo" -> "value"))
//=> Doc2(None), but expected Doc2(Some(Foo("value")))


/** This is O.K. The custom transformer is used for `foo` */
val doc1Grater = grater[Doc1]

doc1Grater.asDBObject(Doc1(Foo("value")))
//=> {"foo": "value"} as it is expected.

doc1Grater.asObject(DBObject("foo" -> "value"))
//=> Doc1(Foo("value")) as expected
```

Am I missing something?

Thanks,
Yusuke


--
Btw, I'm using Salat on my production systems and its working like a charm. Thanks :)

--
You received this message because you are subscribed to the Google Groups "scala-salat" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-salat...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Duncan Crawford

unread,
May 8, 2013, 12:09:52 PM5/8/13
to scala...@googlegroups.com
Has this been fixed in 1.9.2-SNAPSHOT?
Reply all
Reply to author
Forward
0 new messages