Skip to content

ConfiguredJsonCodec example failing #722

Closed

Description

@eliaslevy

This simple example, given on the documentation, fails on Scala 2.11.11:

import io.circe.generic.extras._, io.circe.syntax._

@ConfiguredJsonCodec case class Bar(@JsonKey("my-int") i: Int, s: String)

Bar(13, "Qux").asJson

with the error:

<console>:17: error: could not find Lazy implicit value of type io.circe.generic.extras.decoding.ConfiguredDecoder[Bar]
       @ConfiguredJsonCodec case class Bar(@JsonKey("my-int") i: Int, s: String)

to fix it, one must define the implicit to return the Configuration within the class' object:

object Bar {
  implicit val config: Configuration = Configuration.default
}

Activity

  1. travisbrown commented on Aug 4, 2017

    @travisbrown
    Member

    Good catch. The problem here is that all of the code blocks on the page are compiled with the previous blocks' definitions in context, so this example is picking up the configuration from the previous block.

    In this case the configuration could go either in the companion object or in any enclosing scope. I don't have a strong opinion about which we should use in these docs, but definitely think each example should contain its own Configuration definition (if it uses one).

  2. orlandojsjr commented on Oct 5, 2017

    @orlandojsjr

    This example keeps falling for me.
    I'm using Scala Version 2.12.3

  3. froth commented on Apr 4, 2019

    @froth
    Contributor

    This has been fixed in the meantime by @gvolpe . Current examples work fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions