Map[Boolean, T] fails to encode with 'could not find Lazy implicit value of type DerivedAsObjectEncoder[Foo]'
See original GitHub issueBuild Details
Circe : 0.14.0-M1 Scala : 2.12.10
Problem
If there is a case class, with an element that is a Map
where key is Boolean
, the encoding fails with an unclear error message
could not find Lazy implicit value of type io.circe.generic.encoding.DerivedAsObjectEncoder[Foo]
not enough arguments for method deriveEncoder: (implicit encode: shapeless.Lazy[io.circe.generic.encoding.DerivedAsObjectEncoder[Foo]])io.circe.Encoder.AsObject[Foo].
Unspecified value parameter encode.
Code
import io.circe.Encoder
import io.circe.syntax._
import io.circe.generic.semiauto.deriveEncoder
case class Foo(boolKeyMap: Map[Boolean, String])
object Foo {
implicit val encFoo: Encoder[Foo] = deriveEncoder[Foo]
}
println(
Foo(boolKeyMap = Map(true -> "str")).asJson.spaces2
)
Scastie link
https://scastie.scala-lang.org/0PSRfw5JRASQGBEcHyWAhA
Question
I’m wondering if this is intended behavior and if so, is there scope of improving the error message.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:5 (3 by maintainers)
Top Results From Across the Web
could not find Lazy implicit value of type io.circe.generic ...
could not find Lazy implicit value of type io.circe.generic.encoding.DerivedAsObjectEncoder (Map custom key) #1626.
Read more >Circe deriveDecoder/deriveEncoder could not find Lazy ...
Circe deriveDecoder/deriveEncoder could not find Lazy implicit value of type io.circe.generic.encoding.DerivedAsObjectEncoder · Ask Question.
Read more >circe/circe - Gitter
Error:(32, 68 ) could not find Lazy implicit value of type io.circe.generic.decoding.DerivedDecoder[Operation] implicit val OperationDecoder: ...
Read more >Circe deriveDecoder/deriveEncoder could not find Lazy ...
Coding example for the question Circe deriveDecoder/deriveEncoder could not find Lazy implicit value of type io.circe.generic.encoding.
Read more >Implicits guide for custom types — tapir 0.x documentation
A could not find implicit value error can be sometimes puzzling, ... In general, when using a custom type in any context, an...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@praateekmahajan I think the problem with us implementing a
Boolean
KeyEncoder
orKeyDecoder
is going to be choosing a canonical representation. For all the key encoder/decoders so far there is a very clear representation to choose, including URI and UUID. But for boolean, do we go withTRUE
,true
,True
, or1
? We cannot choose all of them, because you could have multiple of those keys within a Json Objects. I think the safest thing for us, as a library would be to let any user who needs aKeyEncoder[Boolean]
to implement the specific one they want.For instance, you could add this next to your encoder and solve your problem, with a bonus decoder too: (scastie link)
Thank you for engaging in the conversation, I agree it’s not common and could be better defined in a case class with two values.
For my understanding, would there be a reason to not add the Boolean encoder to
KeyEncoder
? Not common is a good reason that it isn’t already there but wondering if it’s a good enough reason to not include it further (assuming the time to create and merge the PR is free)? I see URI in the KeyEncoder which makes me think that’s a further rarer key, yet possible key, similarly Boolean, rare key yet possible.