Getting Lift-Json to serialize java.sql.Date like java.util.Date

106 views
Skip to first unread message

Maxime Lévesque

unread,
May 29, 2013, 1:07:59 PM5/29/13
to liftweb
I'd like to get Lift-Json to
Getting Lift-Json to serialize java.sql.Date the same way as java.util.Date.
I use losslessDate serialization.

I'm aware that this implies that all dates will unserialize as
java.util.Date, and
I'm fine with that.

What is the best way to do this ?


THanks


--
Stability Is Destabilizing

-- Hyman Minsky

Joni Freeman

unread,
May 29, 2013, 2:44:46 PM5/29/13
to lif...@googlegroups.com
Hi,

You can define a custom serializer for unsupported types. Custom serializer for
java.sql.Date would probably be very similar to this:

https://github.com/lift/framework/blob/master/core/json-ext/src/main/scala/net/liftweb/json/ext/JodaTimeSerializer.scala#L65

Basically you define a pair of functions which know how to convert to/from JSON and
then register that serializer to your configuration:

implicit val formats = DefaultFormats ++ MyCustomSerializer

Cheers Joni

Maxime Lévesque

unread,
May 29, 2013, 4:11:14 PM5/29/13
to lif...@googlegroups.com

Thanks, that worksed beautifully ! 
Reply all
Reply to author
Forward
0 new messages