Search code examples
scalaplayframework-2.0jacksonscala-2.10jerkson

Json serialization in Scala 2.10


Before Play 2.1 and Scala 2.10 I used Jerkson.

Unfortunatly there is no officially released Jerkson version compatible with Scala 2.10 (yet).

I'm since using Jackson with Scala module but I don't have the desired behavior with Enumerations.

I'm trying to use Play 2.1 Reads, Writes and Format, using macro inception but it seems really painful and I need to add boilerplate stuff to my models so that the inception works:

object User extends ((String, String, Option[String], Option[String], Long, Long, Boolean, Boolean, ObjectId) => User) {
 ...
}

Then I can use implicit val userFormat: Format[User] = Json.format[User]

And I still can't dynamically serialize an Object, but just an User

I didn't look at Lift but it seems to add as much as boilerplate code as Play2.1 Json library.


I think serialization should be easy in any langage. I don't want to write custom serializers or custom parsers.

I expect the library to work with a code like that:

case class User(name: String, status: Status.Value)
val myUser = User("toto",Status.VALID)
val myMap: Map[String,Object] = ("key1" -> myUser, "key2" -> "value2")
Json.serialize(myMap)

This is what is provided in Java with Gson, Jackson and other tools like that.


So with Scala 2.10 I don't know which tool to use. And I don't understand why we would need to build custom serializers for such simple cases. Maybe Play2.1 Json is faster because it is Macro based but isn't there a possibility so that if there is no Format provided it uses reflection or something?

Do you know any tool that coold be appropriate for my usecase?


Solution

  • I replaced my Jerkson code by Jackson Scala Module and it works fine