Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compile fails in scala 3 with implicit errors for circe #642

Open
Marcus-Rosti opened this issue Oct 8, 2021 · 3 comments
Open

Compile fails in scala 3 with implicit errors for circe #642

Marcus-Rosti opened this issue Oct 8, 2021 · 3 comments

Comments

@Marcus-Rosti
Copy link

this passes

        complete(ToResponseMarshallable(MyResponse(???))(marshaller[MyResponse]))

but this fails

        complete(MyResponse(???))

with error

[error] 21 |        complete(MyResponse(???))
[error]    |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[error]    |Found:   my.dumb.class.MyResponse
[error]    |Required: akka.http.scaladsl.marshalling.ToResponseMarshallable
[error]    |
[error]    |One of the following imports might make progress towards fixing the problem:
[error]    |
[error]    |  import akka.http.impl.util.JavaMapping.Implicits.convertToScala
[error]    |  import akka.http.javadsl.server.RoutingJavaMapping.Implicits.convertToScala
[error]    |
[error] Explanation
[error] ===========
[error] 
[error] I tried to show that
[error]   my.dumb.class.MyResponse
[error] conforms to
[error]   akka.http.scaladsl.marshalling.ToResponseMarshallable
[error] but the comparison trace ended with `false`:

My guess is that using circe in scala3, caused some drift with akka-http-json

@hseeberger
Copy link
Owner

Akka does not yet support Scala 3.

@godenji
Copy link

godenji commented Nov 5, 2021

Akka does not yet support Scala 3.

It does now, although akka-http is still lagging in this department, iirc.

@AvaPL
Copy link

AvaPL commented Jan 22, 2022

My workaround for this issue was to use crosscompiled Akka together with circe for Scala 3. Here is my minimal sbt config:

val circeVersion = "0.14.1"
val akkaVersion = "2.6.18"
val akkaHttpVersion = "10.2.7"
val akkaHttpCirceVersion = "1.39.2"

lazy val circeCore = "io.circe" %% "circe-core" % circeVersion
lazy val circeGeneric = "io.circe" %% "circe-generic" % circeVersion
lazy val circeParser = "io.circe" %% "circe-parser" % circeVersion
lazy val akkaStream = "com.typesafe.akka" %% "akka-stream" % akkaVersion
lazy val akkaHttp = "com.typesafe.akka" %% "akka-http" % akkaHttpVersion
lazy val akkaHttpCirce = "de.heikoseeberger" %% "akka-http-circe" % akkaHttpCirceVersion

lazy val scala3cross2 = project
  .settings(
    scalaVersion := "3.1.0",
    libraryDependencies ++= List(
      circeCore,
      circeGeneric,
      circeParser
    ) ++ List(
      akkaStream,
      akkaHttp,
      akkaHttpCirce
    ).map(
      _.cross(CrossVersion.for3Use2_13)
    ),
    conflictWarning := ConflictWarning.disable
  )

Now you can use Scala 3 circe syntax for codecs on case classes:

import io.circe.Codec

case class Example(value: String) derives Codec.AsObject

This setup works exactly like using io.circe.generic.auto.* in 2.13 and the error is gone. I'm currently using it with FailFastCirceSupport with no issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants