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

Diverging implicits when building serializer for generic types. #21

Open
sherzodv opened this issue Jun 22, 2018 · 1 comment
Open

Diverging implicits when building serializer for generic types. #21

sherzodv opened this issue Jun 22, 2018 · 1 comment
Assignees
Labels

Comments

@sherzodv
Copy link

Hi, thank you for a cool project!

I've encountered the issue with resolving implicits, here is somewhat minimal case reproducing error in header:

trait Res[+A] extends Product {
  def code: Res.Code
}

object Res {
  sealed trait Code
  final case object Succ extends Code
  final case object Fail extends Code

  final case class Ok[A](data: A, code: Code = Succ) extends Res[A]
  final case class Error[A](message: String, code: Code = Fail) extends Res[A]
}

final case class Item(name: String)

package object implicits {
  import tethys._
  import tethys.jackson._
  import tethys.derivation.semiauto._

  implicit val itemReader: JsonReader[Item] = jsonReader[Item]
  implicit val itemWriter: JsonObjectWriter[Item] = jsonWriter[Item]

  implicit def resReader[A: JsonReader]: JsonReader[Res[A]] = 
    JsonReader.builder
      .addField[String]("code")
      .selectReader[Res[A]]{
        case "SUCCESS" => JsonReader.builder.addField[A]("data").buildReader(Res.Ok[A](_))
        case "FAILURE" => JsonReader.builder.addField[String]("message").buildReader(Res.Error[A](_))
      }

  implicit def okWriter[A: JsonObjectWriter]: JsonObjectWriter[Res.Ok[A]] =
    JsonWriter.obj[Res.Ok[A]]
      .addField("code")(_ => "SUCCESS")
      .addField("data")(_.asJson)
  implicit val errorWriter: JsonObjectWriter[Res.Error[_]] =
    JsonWriter.obj[Res.Error[_]]
      .addField("code")(_ => "FAILURE")
      .addField("message")(_.message)
}

...

>>>          Ok(List(Item("a"), Item("b"))).asJson
...
> diverging implicit expansion for type tethys.JsonWriter[List[io.expload.api.Item]]
@eld0727 eld0727 added this to the v0.6.4 milestone Jun 22, 2018
@eld0727 eld0727 added the bug label Jun 22, 2018
@eld0727 eld0727 self-assigned this Jun 22, 2018
@eld0727 eld0727 modified the milestones: v0.9.1, v0.10.0 Jul 2, 2019
@eld0727
Copy link
Collaborator

eld0727 commented Jul 2, 2019

@sherzodv that example is not correct because okWriter requires JsonObjectWriter for A and List does not have it

Do you have better example to reproduce this issue?

@eld0727 eld0727 removed this from the v0.10.0 milestone Jul 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants