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

kebs-circe - StackOverflowError when deriving codecs using NoFlat variant #322

Open
pk044 opened this issue Oct 13, 2023 · 0 comments
Open
Labels

Comments

@pk044
Copy link
Collaborator

pk044 commented Oct 13, 2023

The problem can be reproduced with the test below (it should also be added to CirceFormatNoFlatTests along with the fix)

  object KebsProtocol extends KebsCirce with KebsCirce.NoFlat
  import KebsProtocol._

  case class R(a: Int, rs: Seq[R])

  test("Recursive format") {
    val decoder = implicitly[Decoder[R]]
    val encoder = implicitly[Encoder[R]]


    decoder.apply(
      Json
        .fromFields(Seq("a" -> Json.fromInt(1), "rs" -> Json.arr(Json.fromFields(Seq("a" -> Json.fromInt(2), "rs" -> Json.arr())))))
        .hcursor) shouldBe Right(R(1, Seq(R(2, Seq.empty[R]))))
    encoder.apply(R(1, Seq(R(2, Seq.empty[R])))) shouldBe Json.fromFields(
      Seq("a" -> Json.fromInt(1), "rs" -> Json.arr(Json.fromFields(Seq("a" -> Json.fromInt(2), "rs" -> Json.arr())))))
  }

Workaround: Add codecs using circe's semi-auto derivation. Example:

trait JsonProtocol
    extends FailFastCirceSupport
    with KebsCirce
    with KebsCirce.NoFlat
    with KebsEnumFormats
    with TimeInstances
    with UtilInstances
    with NetInstances {
  implicit val decoder: Decoder[Thing] = deriveDecoder[Thing]
  implicit val encoder: Encoder[Thing] = deriveEncoder[Thing]
}
@pk044 pk044 added the bug label Oct 13, 2023
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

1 participant