softwaremill / sttp

The Scala HTTP client you always wanted!
https://sttp.softwaremill.com
Apache License 2.0
1.46k stars 309 forks source link

Support for circe with Scala 3 #864

Closed bilal-fazlani closed 3 years ago

bilal-fazlani commented 3 years ago
private val version = "3.1.2"
lazy val `sttp-circe` = "com.softwaremill.sttp.client3" % "circe_2.13" % version

results into

[error]   Not found
[error]   not found: /Users/bilal/.ivy2/local/com.softwaremill.sttp.client3/circe_3.0.0-M3/3.1.2/ivys/ivy.xml
[error]   not found: https://repo1.maven.org/maven2/com/softwaremill/sttp/client3/circe_3.0.0-M3/3.1.2/circe_3.0.0-M3-3.1.2.pom
[error]   not found: https://jcenter.bintray.com/com/softwaremill/sttp/client3/circe_3.0.0-M3/3.1.2/circe_3.0.0-M3-3.1.2.pom
[error] (ssExtractDependencies) sbt.librarymanagement.ResolveException: Error downloading com.softwaremill.sttp.client3:circe_3.0.0-M3:3.1.2
[error]   Not found
adamw commented 3 years ago

Only circe 0.14.0-M3 is published for scala3, and there are some incompatible changes:

[error] -- Error: sttp/json/circe/src/test/scala/sttp/client3/circe/CirceTests.scala:17:37
[error] 17 |    val req = basicRequest.body(body)
[error]    |                                     ^
[error]    |no implicit argument of type sttp.client3.BodySerializer[CirceTests.this.Outer] was found for an implicit parameter of method body in trait RequestTExtensions.
[error]    |I found:
[error]    |
[error]    |    sttp.client3.circe.circeBodySerializer[CirceTests.this.Outer](this.Outer.encoder
[error]    |      ,
[error]    |    /* missing */summon[io.circe.Printer])
[error]    |
[error]    |But no implicit values were found that match type io.circe.Printer.

so I suppose I'll have to wait until 0.14 to release for scala3 (and scala2 alike)

adamw commented 3 years ago

We could do separate sources, but now after upgrading to Scala3-RC1, circe isn't published yet

bilal-fazlani commented 3 years ago

I guess it's worth waiting. Thanks 👍

aeons commented 3 years ago

0.14.0-M4 is out now, with 3.0.0-RC1 support.

adamw commented 3 years ago

The error seems to come from default implicit arguments here:

implicit def circeBodySerializer[B](implicit
      encoder: Encoder[B],
      printer: Printer = Printer.noSpaces
  ): BodySerializer[B] 

anybody knows if this changed somehow in Scala3? The 3-RC1 compiler can't find the printer implicit, though it has a default value

aeons commented 3 years ago

I fought a bit with that as well, without getting anywhere. I couldn't find a relevant changelog or reproduce it in a smaller example.

aeons commented 3 years ago

Hah, I was just preparing to commit a workaround for this. :D

adamw commented 3 years ago

Was it the same workaround? :)

aeons commented 3 years ago

Yep. I filed a bug in the dotty repo as well, but it's not really easy to create a minimal reproduction of it.

adamw commented 3 years ago

Ah, good that you let the dotty team know. Thanks! :)

adamw commented 3 years ago

Released in 3.1.5