Hi,
Serializing joda-time is not supported. Last week a type hint
mechanism was added to support serialization of polymorphic Lists.
This could be generalized a bit so that users can provide de-/
serializers for any type. This could be done for instance using a pair
of partial functions. Something like:
type TypeHint = String
def serialize: PartialFunction[Any, JValue]
def deserialize: PartialFunction[(TypeHint, JValue), Any]
Then a support to serialize joda-time DateTime could be implemented
as:
def serialize(a: Any) = a match {
case d: DateTime = JString(t, toString(d))
}
def deserialize(hint: TypeHint, json: JValue) = (hint, json) match {
case (DateTime, JString(t, JString(t)) = mkDateTime(t)
}
I'm in a middle of something else right now but will look into this
next.
Cheers Joni
On 25 loka, 14:27, Christophe Dehlinger
christophedehlin...@gmail.com wrote:
Hi,
Is there a way to configure lift-json's case class serialization so that it
uses Joda DateTimes instead of java.util.Date ?
I'd like to known how to make the simple following code work as expected:
import net.liftweb.json._
import org.joda.time._
case class MyCaseClass(dt: DateTime)
object TestMain {
def main(args: Array[String]) {
implicit val formats = DefaultFormats
println(Serialization.read[MyCaseClass]({ dt :
2009-10-25T12:50:37.560+01:00 }))
println(Serialization.write(MyCaseClass(new DateTime)))
}
}
(running this code yields:
MyCaseClass(2009-10-25T12:57:03.366+01:00) -- current date when the
program was run, not the date in the code
{}
)
More generally, is there a way to customize lift-json's serialization
mappings, in particular the types lift-json sees as primitive ?
The class I'm actually interested in serializing has many fields whose type
is a non-case class MyRichFloat with a single Float field. It would be
really nice if I could (de)serialize these into JSON floats.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups
Lift group.
To post to this group, send email to liftweb@googlegroups.com
To unsubscribe from this group, send email to
liftweb+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/liftweb?hl=en
-~--~~~~--~~--~--~---