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.

Custom encoders/decoders example failing with Scala 2.11.x

See original GitHub issue

The example from the documentation fails on Scala 2.11.11, but I can run it successfully on Scala 2.12.x

scala> class Thing(val foo: String, val bar: Int)
defined class Thing

scala> implicit val encodeFoo: Encoder[Thing] = new Encoder[Thing] {
     |   final def apply(a: Thing): Json = Json.obj(
     |     ("foo", Json.fromString(a.foo)),
     |     ("bar", Json.fromInt(a.bar))
     |   )
     | }
encodeFoo: io.circe.Encoder[Thing] = $anon$1@bfe134d

scala> implicit val decodeFoo: Decoder[Thing] = new Decoder[Thing] {
     |   final def apply(c: HCursor): Decoder.Result[Thing] =
     |     for {
     |       foo <- c.downField("foo").as[String]
     |       bar <- c.downField("bar").as[Int]
     |     } yield {
     |       new Thing(foo, bar)
     |     }
     | }
<console>:17: error: value flatMap is not a member of io.circe.Decoder.Result[String]
             foo <- c.downField("foo").as[String]
                                         ^
<console>:18: error: value map is not a member of io.circe.Decoder.Result[Int]
             bar <- c.downField("bar").as[Int]

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:1
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

32reactions
nsanglarcommented, Nov 13, 2017

To overcome this issue you can use cats either, simply import it: import cats.syntax.either._

0reactions
travisbrowncommented, Nov 22, 2018

@djvulee This has slipped through the cracks, but a PR would be very welcome.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Scala 2.11.0 - The Scala Programming Language
Use Scastie to run single-file Scala programs in your browser using multiple Scala compilers; the production Scala 2.x compilers, Scala.js, Dotty, and Typelevel ......
Read more >
How do I change intellij idea to compile with scala 2.11?
In IntelliJ 2016.x you upgrade Scala by. Ensure Scala Plugin up to date. Then by going to: File | Other Settings | Default...
Read more >
circe/circe - Gitter
... date: Option[java.sql.Date]). I am guessing I have to write a custom encoder/ decoder for it. Can some show a sample how to...
Read more >
Installation · Scalafix - Scala Center
Every pull request is tested on both Linux and Windows. Java 8 or Java 11. Scala 2.11, 2.12 or 2.13. Scala 3.x: Scala...
Read more >
The Scala Plugin - Gradle User Manual
Just like the Java plugin, the Scala plugin allows you to configure custom locations for Scala production and test source files. Example 2....
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