Liftweb JSON serialization and deserialization using Scala

Reading Time: 2 minutes

We are working on a Scala project using Play framework. We had written the Serializers and Deserialzers for parsing the JSON data that contains different data types like ObjectId , Scala Enumeration etc. We are using net.liftweb.json for writing and parsing the JSON data.

We were having the JSON looks like as :

[{“id”:1,”school”:”Cambridge”,”year”:{“name”:”FirstYear”},”major”:”Science”,”degree”:{“name”:”Bachelor’s”},”Date”:”01/05/2011″}]

The year field here is an scala enumeration and the Date has to be parsed as java.util.Date. We were end up with the following error for the enumeration:

We had written the customized serializers and deserializers for different data types. Here i am going to elaborate some of the important ones.

Enumeration Serializer and Deserializer

DateTime Serializers and Deserializer

ObjectID Serializers and Deserializer

We can parse the date by overriding the dateFormatter method as well.