propensive / rapture

Rapture
183 stars 39 forks source link

Problem with Serializers of case classes that contain Map[Int,Int] #238

Open johannegger opened 7 years ago

johannegger commented 7 years ago

the following code does not compile:


import rapture.json.{Json, _}

case class Foo(value:Map[Int,Int])
case class Bar(foos:Seq[Foo])

class Test(implicit ast:JsonAst) {

  val myBar = Bar(List(Foo(Map(1->1))))
  //implicit val ser = implicitly[Serializer[Foo,Json]]
  Json(myBar)
}

but removing the commented implicit solves the error. The error for scala 2.10 doesn't help much:

Cannot serialize type com.example.Bar to rapture.json.Json. Please provide an implicit Serializer of type com.example.Bar.

However using 2.11 we get:

diverging implicit expansion for type rapture.json.Serializer[com.example.Bar,rapture.json.Json]

this leads me to suspect a problem related to the Map[Int,Int] - Maybe there are different strategies for maps that use keys other than String?

tyrcho commented 6 years ago

I've tried to reproduce your workaround, but without success. Here is my minimalist project: https://github.com/tyrcho/rapture-json-demo/blob/map/src/main/scala/BiggerDemo.scala

It could be because I'm still in 1.1.0 ... But I cannot migrate to 2.0 because of #278