Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does N in jsonFormatN in spray mean?

I'm looking at the code of "Akka and Spray" tutorial in Typesafe's Activator, written by eigengo. I do not get where jsonFormat1, jsonFormat2, ... jsonFormatN is defined and how it does what it does.

implicit val sendMessageFormat = jsonFormat2(SendMessage)

The above snippet is in scala > api > MessengerService.scala

Thank you.

like image 436
jerielmari Avatar asked Jun 01 '15 03:06

jerielmari


1 Answers

Basically, the N in jsonFormatN denotes the number of parameters of the class that you are trying to Marshall/Unmarshall.

An excerpt from the link posted by Ashalynd:

The jsonFormatX methods reduce the boilerplate to a minimum, just pass the right one the companion object of your case class and it will return a ready-to-use JsonFormat for your type (the right one is the one matching the number of arguments to your case class constructor, e.g. if your case class has 13 fields you need to use the jsonFormat13 method).

like image 81
jerielmari Avatar answered Oct 18 '22 14:10

jerielmari