In my previous blog, I talked about how uPickle works. Now I will be comparing it will many other json serializers where I will be serializing and deserializing scala case class.

Before that let me discuss all the json serializers that I have used in my comparison. I will compare uPickle with PlayJson, Circe and Argonaut.

You can get all the code that I will explain in my github repository. Now, let’s see the code:

case class Product(brand: String, model : String)

object Product {
  implicit val playJsonFormatter  = Json.format[Product]     //For PlayJson
  implicit def uPickleFormatter: ReadWriter[Product] = macroRW  //For uPickle
  implicit def PersonCodecJson =
    casecodec2(Product.apply, Product.unapply)("brand", "model")   //For Argonaut

This is the case class which contains all the implicit JSON formatters.

Now lets take a product object for our examples and a json string that will be de-serialized back to product object.

val product = Product("Samsung", "12JF3DE")
val jsonString = "{\"brand\":\"Samsung\",\"model\":\"12JF3DE\"}"

Play JSON Serializer

To serialize the above case class.

val playJson = Json.toJson(product)

To deserialize the above case class.

val myPickle = Json.parse(jsonString).as[Product]

Argonaut JSON Serializer

To serialize

val argonautJson: Json = product.asJson

To deserialize

val parsed: Option[Product] = jsonString.decodeOption[Product]

Circe JSON Serializer

To serialize

val circeJson = product.asJson.noSpaces

To deserialize

val myPickle = decode[Product](jsonString)

uPickle JSON Serializer

To serialize

val upickleJson = write(product)

To deserialize

val upickleJson = read[Product](jsonString)


After comparing all these uPickle is faster than all these. See the screenshot below.


We can see that the execution time of uPickle is less both in serializing and deserializing.

Try it Yourself from here.

In my next blog I will talk about uJson which is the subset of uPickle and will talk about how we can transform it to other json serializers.

Happy reading….!!


uPickle Documentation


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.