I have an empty case class corresponding to an HTTP GET request:
case class GetFoo() extends MyQueryRequest {
// ...
}
and each message has a companion object with describes its implicit JSON writer and reader:
object GetFoo extends MyImplicitJsonProvider[GetFoo] {
implicit val write = Json.writes[GetFoo]
implicit val read = Json.reads[GetFoo]
}
However, because GetFoo
takes no parameters, there's no way to (de)serialize it:
Unapply of object
GetFoo
has no parameters. Are you using an empty case class?
A workaround to inject a dummy Boolean variable into the constructor for GetFoo
, but this is a kludge. I'd like to make GetFoo
(de)serializable as an empty JSON object. How can I do that?
Since GET requests don't send data, it would be even better to make the reader/writer throw an exception if it were being used since the request shouldn't need to be written or read ever, but is required by the extended class.
My design relies on the GetX
class extending MyQueryRequest
and and the GetX
companion object extending MyImplicitJsonProvider[GetX]
.