Now I wanna serialize/deserialize Json data, and there are several json libraries to choose. However, they use different context-bounds for encoding/decoding, which make it hard to define a trait for them.
trait JsonLib {
// def writes[T](data: T): String
// def reads[T](jsonStr: String): Option[T]
}
object JsonCirce extends JsonLib {
import io.circe.Encoder._
import io.circe.Decoder._
def writes[T: Encoder](data: T): String = ...
def reads[T: Decoder](jsonStr: String): Option[T] =
}
//spray-json
object JsonSpray extends JsonLib {
import spray.json._
def writes[T: JsonWriter](data: T): String = ...
def reads[T: JsonReader](jsonStr: String): Option[T] = ...
}
Is there a way to define the writes/reads in the trait?