Examples of using jsonFormat to spray
I ran into this problem while trying to implement a JsonFormat object for a case class that is generic. This is my class:
case class SimpleQuery[T](field : String, op : Operator, value : T) extends Query{
def getType = ????
}
I am trying to use the format the json spraying github tips page looks like this:
implicit def SimpleQueryJsonFormat[A <: JsonFormat] = jsonFormat4(SimpleQuery.apply[A])
But I am getting this compiler error
trait JsonFormat takes type parameters
Example from json github atomizer page:
case class NamedList[A](name: String, items: List[A])
object MyJsonProtocol extends DefaultJsonProtocol {
implicit def namedListFormat[A :JsonFormat] = jsonFormat2(NamedList.apply[A])
}
It looks like mine.
I'll also open the issue on the github page.
Thank you in advance
source to share
I think you can deceive <:
and :
to determine the type of the parameter.
In yours, it [A <: JsonFormat]
means " A
extends JsonFormat
".
In the example it [A :JsonFormat]
means " A
with implicit JsonFormat[A]
". This is the same as requiring an implicit (but unnamed) parameter, for example implicit aFormat: JsonFormat[A]
. This is required to format part of value: T
your class.
TL; DR, try switching <:
to a:
source to share