I am trying to make a generic mapper from a JValue (from json4s) to a Scala case class (with contains spire numeric existential type) and vice versa having the scala case class similar to :
case class SomeStat[T : Numeric](a:T, b:T)
for the generic mapper I have something like:
final class SynchronizerClass[B : Numeric, A <: SomeStat[B]](implicit manifest: Manifest[B], a:Manifest[A])
{format => (
{case j:JValue => {
implicit val formats = format
def extractNumber(j:JValue) = {
for {
a <- scala.util.Try((j \ "a").extract[B]).toOption
b <- scala.util.Try((j \ "b").extract[B]).toOption
} yield {
SomeStat(a,b).asInstanceOf[A]
}
}
(extractNumber(j)) getOrElse {
throw new MappingException("Invalid Number Type")
}
}},
{case x:SomeStat[A] =>
implicit val formats = format
Map(
"a" -> Extraction.decompose(x.a),
"b" -> Extraction.decompose(x.b)
)}
)}
the problem is that spire implicit has two for Numeric, as an example I am trying to construct something like this
val j:JValue = ??? // Some Json Value
val someStat = Extraction.decompose(SomeStat[BigDecimal](j))