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

Custom encoders/decoders example failing with Scala 2.11.x #756

Closed
allantl opened this issue Sep 22, 2017 · 7 comments
Closed

Custom encoders/decoders example failing with Scala 2.11.x #756

allantl opened this issue Sep 22, 2017 · 7 comments

Comments

@allantl
Copy link
Contributor

allantl commented Sep 22, 2017

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]

@zlosim
Copy link

zlosim commented Oct 20, 2017

got the same error on scala 2.10.6

@mborra
Copy link

mborra commented Oct 23, 2017

I have the same issue on Scala 2.11, with Circe 0.5.2 version

@mborra
Copy link

mborra commented Oct 23, 2017

I think the problem is that the Scala 2.11.x Either does not have the map/flatMap, the new methods are introduced in the 2.12 version

@nsanglar
Copy link

nsanglar commented Nov 13, 2017

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

@libratiger
Copy link

Why not update this in the document? new users may get stuck in this problem.

@travisbrown
Copy link
Member

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

@hamnis
Copy link
Collaborator

hamnis commented Jul 27, 2023

2.11 is no longer supported

@hamnis hamnis closed this as completed Jul 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants