-
Notifications
You must be signed in to change notification settings - Fork 65
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
Implicit EntityEncoder for circe Encoder breaks compilation #216
Comments
Curious, since I believe the interesting part is that there isn't any need for the |
@bryce-anderson in this code there's indeed no need for |
@bryce-anderson the problem resolves if I disable partial unification |
Interesting. |
that |
@SystemFw yes, I don't think that's related, the error in http4s/http4s#1648 was caused by |
The puzzling thing here is the interaction with partial unification. |
I have the same problem. circe.generic.auto works fine for EntityDecoders but not Encoders with Rho... |
I fixed it by hard encoding the import statements in the right order : It's a conflict of implicits between rho.bits, circe and http4s.circe |
@Igosuki could you post a full example? |
@nightscape did you happen to find a workaround? ) |
Unfortunately not... I converted the problematic code to pure Http4s and left the rest in Rho. |
Two things to do @nightscape @DStranger
here's the encoders def I'm using :
|
Perhaps someone can open a PR to the |
I haven't investigated where the problem comes from exactly since I didn't know the codebase until my last PR... I suspect it has to do with Circe's macros which conflict with rho's Kleisli's and shapeless. |
Typically, you can get a similar type of error if you use circe.generic.auto and sealed traits with noKnownSubclasses until scala 2.12.4 it's a question of what class gets resolved first when the compiler reaches a certain phase. |
Not sure if it is exactly same, but I see class MinimalService[F[_]: Sync](swaggerSyntax: SwaggerSyntax[F]) extends RhoService[F] {
import swaggerSyntax._
"Example route" **
POST / "endpoint" ^ jsonDecoder[F] |>> { _: Json =>
if (true) Ok("ok") else Forbidden("forbidden")
}
}
Works fine either without decoding or with single HTTP status. UPD: tying |
Yeah that's because with IO you can directly pull the concrete IO dsl, which isn't possible with just F : Effect |
So I'm having the same issue, I think. The following code works, but if I try to do something like class ProductRoutes[M[+_]: Effect, F[_]](swaggerSyntax: SwaggerSyntax[M])(F: ProductSyntax[M]) extends RhoRoutes[M] {
import swaggerSyntax._
import io.circe.generic.auto._
import org.http4s.circe.{jsonOf, jsonEncoderOf}
implicit def productEntityEncoder: EntityEncoder[M, ProductRepresentation] = jsonEncoderOf[M, ProductRepresentation]
implicit def errorEntityEncoder: EntityEncoder[M, ServiceError] = jsonEncoderOf[M, ServiceError]
implicit def productEntityDecoder: EntityDecoder[M, ProductRepresentation] = jsonOf[M, ProductRepresentation]
implicit def errorEntityDecoder: EntityDecoder[M, ServiceError] = jsonOf[M, ServiceError]
"We don't want to have a real 'root' route anyway..." **
GET |>> TemporaryRedirect(Uri(path = "/swagger-ui"))
"This route allows you to post stuff" **
POST / "post" ^ EntityDecoder.text[M] |>> {
body: String => Ok("you posted " + body)
}
"This route allows you to get the product" **
GET / "product" / pathVar[String] |>> {
id: String => F.getProduct(id)
}
"Endpoint for creating product" **
PUT / "product" ^ EntityDecoder[M, ProductRepresentation] |>> {
product: ProductRepresentation => F.createProduct(product)
}
} But it doesn't work if I modify the code to do something like this: "This route allows you to get the product" **
GET / "product" / pathVar[String] |>> {
id: String =>
F.getProduct(id) map {
case Some(prod) => Ok(prod)
case None => NotFound(ServiceError(s"$id does not exist"))
}
} |
@ChetanBhasin your issue is Also, just random note, |
Hi guys,
The following code doesn't compile with a
could not find implicit value for parameter hltf: org.http4s.rho.bits.HListToFunc[F,String :: shapeless.HNil,String => F[Test.this.Ok.T[String]]]
.Removing
autoEncoder
, or removing theio.circe.Encoder
constraint fixes the problem.The text was updated successfully, but these errors were encountered: