New feature: first cut of @Persist annotation

32 views
Skip to first unread message

rktoomey

unread,
Feb 26, 2011, 1:50:46 PM2/26/11
to scala-salat
Greetings,

Salat 0.0.6-SNAPSHOT now has an @Persist annotation that lets you
persist a value outside the case class contructor when serializing a
case class object,

So when an instance of this case class is serialized asDBObject, the
resulting dbo will have a value for "toSea".
case class Maud(swept: String, out: String) {
@Persist val toSea = "%s %s".format(out.reverse, swept.reverse)
}

When that dbo is deserialized back to an instance of case classMaud,
the serialized value for toSea is thrown away.

The idea behind @Persist loosely defined here:
https://github.com/novus/salat/issues#issue/3

See spec here for examples of how to use @Persist:
https://github.com/novus/salat/blob/master/src/test/scala/com/novus/salat/test/PersistAnnotationSpec.scala

Please note that putting @Persist on a field in an abstract superclass
or trait doesn't work yet (the last part of the spec marked
"pendingUntilFixed"), although I do intend to make it work soon.

Please try it out and see if you find it useful. The next step is to
include @ForceNotNull which, when used in conjunction with @Persist,
forces a field to a non-null value when serializing.

I am off to Venice for a week, leaving day to day operations of this
list in the capable hands of my colleague Jeff Sack. I hope to have
more exciting features for you when I get back, depending on how much
insomniac jet lagged late night coding I wind up doing.

Best,
Rose
Reply all
Reply to author
Forward
0 new messages