question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Documentation example is not compiling (ADT, ShapesDerivation)

See original GitHub issue

Hello! I am trying to compile the following example. https://circe.github.io/circe/codecs/adt.html

sealed trait Event

case class Foo(i: Int) extends Event
case class Bar(s: String) extends Event
case class Baz(c: Char) extends Event
case class Qux(values: List[String]) extends Event

Precisely I want to use ShapesDerivation, like here:

import io.circe._ // no such line in example, but had to import it
object ShapesDerivation {
  import io.circe.shapes // not used actually
  import shapeless.{ Coproduct, Generic }

  implicit def encodeAdtNoDiscr[A, Repr <: Coproduct](implicit
    gen: Generic.Aux[A, Repr],
    encodeRepr: Encoder[Repr]
  ): Encoder[A] = encodeRepr.contramap(gen.to)

  implicit def decodeAdtNoDiscr[A, Repr <: Coproduct](implicit
    gen: Generic.Aux[A, Repr],
    decodeRepr: Decoder[Repr]
  ): Decoder[A] = decodeRepr.map(gen.from)

}

Didn’t use or write previous GenericDerivation, so no really need to suppress imports?

And this example

import ShapesDerivation._
import io.circe.parser.decode, io.circe.syntax._
decode[Event]("""{ "i": 1000 }""")
(Foo(100): Event).asJson.noSpaces

Doesn’t compile on line decode[Event]("""{ "i": 1000 }"""), gives two errors:

could not find implicit value for evidence parameter of type io.circe.Decoder[com.example.Event]

and

could not find implicit value for parameter encoder: io.circe.Encoder[com.example.Event]

What else do I need? 🤔 Or may be documentation is a bit out of date?

Version if all libraries I use is 0.11.1.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
travisbrowncommented, May 16, 2019

Here’s the minimization that works as expected:

sealed trait Event

case class Foo(i: Int) extends Event
case class Bar(s: String) extends Event
case class Baz(c: Char) extends Event
case class Qux(values: List[String]) extends Event

import io.circe.{ Decoder, Encoder }
import io.circe.generic.auto._, io.circe.shapes._

object ShapesDerivation {
  import shapeless.{ Coproduct, Generic }

  implicit def encodeAdtNoDiscr[A, Repr <: Coproduct](implicit
    gen: Generic.Aux[A, Repr],
    encodeRepr: Encoder[Repr]
  ): Encoder[A] = encodeRepr.contramap(gen.to)

  implicit def decodeAdtNoDiscr[A, Repr <: Coproduct](implicit
    gen: Generic.Aux[A, Repr],
    decodeRepr: Decoder[Repr]
  ): Decoder[A] = decodeRepr.map(gen.from)
}

import ShapesDerivation._

io.circe.parser.decode[Event]("""{ "i": 1000 }""")
1reaction
chrisalbrightcommented, May 21, 2019

@travisbrown I’ll put together some gists and post here. Thanks again.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Scala - Ignore case class field when decoding JSON
I'm playing with the example ADT in ...
Read more >
ADT® Troubleshooting FAQs | How to Fix Your Issue
Having trouble with a smoke detector going off or resetting an alarm panel? Troubleshoot issues with these ADT frequently asked questions.
Read more >
Command and Control Home Security | Help & FAQs - ADT
Get help with your ADT Command touchscreen panel and the ADT Control App with these frequently asked questions. Visit ADT.com/help for more.
Read more >
User Guide - ADT
Smoke detectors also may not sense a fire on another level of a residence or building. A second-floor detector, for example, may not...
Read more >
What if my system is not working properly? - ADT
You can refer to your system owner's manual for system specific help or search the MyADT Help Center for answers to common troubleshooting...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found