akka-http icon indicating copy to clipboard operation
akka-http copied to clipboard

SprayJsonSupport not working for Future[List[obj]] under Scala 3

Open csar opened this issue 2 years ago • 2 comments

val fut = Future.successful(List(Dummy(1),Dummy(2))) complete(fut)

fails to compile under Scala 3.x - works as expected under 2.13.x

Minimal project to show the issue

csar avatar Dec 03 '21 13:12 csar

By spelling out the implicit more, uh, explicitly:

implicitly[ToResponseMarshaller[Future[List[Dummy]]]]

We get a better error message:

[error]    |no implicit argument of type akka.http.scaladsl.marshalling.ToResponseMarshaller[
[error]    |  concurrent.Future[List[Dummy]]
[error]    |] was found for parameter e of method implicitly in object Predef.
[error]    |I found:
[error]    |
[error]    |    akka.http.scaladsl.marshalling.Marshaller.futureMarshaller[A, B](
[error]    |      akka.http.scaladsl.marshalling.Marshaller.liftMarshaller[T](
[error]    |        Run.sprayJsonMarshaller[T](
[error]    |          /* ambiguous: both method immIterableFormat in trait CollectionFormats and method linearSeqFormat in trait CollectionFormats match type spray.json.RootJsonWriter[T] */
[error]    |            summon[spray.json.RootJsonWriter[T]]
[error]    |        , /* missing */summon[spray.json.JsonPrinter])
[error]    |      )
[error]    |    )

This is still rather hard to read, but it says it correctly found 'futureMarshaller', 'liftMarshaller' and sprayJsonMarshaller, but is having trouble finding the right parameters to call sprayJsonMarshaller with.

You can work around this problem for now by performing this step 'manually':

implicit val jsonMarshaller: ToEntityMarshaller[List[Dummy]] = sprayJsonMarshaller(listFormat)

or:

implicit val jsonMarshaller: ToEntityMarshaller[List[Dummy]] = sprayJsonMarshaller(linearSeqFormat)

or:

implicit val jsonMarshaller: ToEntityMarshaller[List[Dummy]] = sprayJsonMarshaller(immIterableFormat)

Not sure why Scala 2 didn't consider these ambiguous and Scala 3 does... especially since with:

implicitly[RootJsonWriter[List[Dummy]]]

both Scala 2 and Scala 3 select an implicit without errors.

raboof avatar Dec 03 '21 16:12 raboof

This still persists with 10.6.0 - any progress?

csar avatar Jan 28 '24 10:01 csar