Case class with Enumeration is not converted
See original GitHub issueI’m trying to convert a case class that has a Enumeration as a argument
import io.circe._, io.circe.generic.auto._, io.circe.jawn._, io.circe.syntax._
object WeekDay extends Enumeration {
val Mon, Tue, Wed, Thu, Fri, Sat, Sun = Value
}
case class test1(day: WeekDay.Value)
case class test2(day: String)
While test2(“Mon”).asJson works as expected:
{
"day" : "Mon"
}
But: test1(WeekDay.Mon).asJson results in:
<console>:27: error: could not find implicit value for parameter encoder: io.circe.Encoder[test] test(WeekDay.Mon).asJson
Is there a way to work around this or is this a bug?
Issue Analytics
- State:
- Created 7 years ago
- Reactions:5
- Comments:5 (4 by maintainers)
Top Results From Across the Web
Case objects vs Enumerations in Scala - Stack Overflow
Case classes naturally supports more fields than a Value based Enumeration which supports a name and ID. The advantages of using Enumerations ......
Read more >Case Objects vs Enumerations in Scala - Baeldung
An enumerated type is a data type that contains only a finite set of named values, and they are supported in most modern...
Read more >Enumerations
Enum case declarations are similar to secondary constructors: they are scoped outside of the enum template, despite being declared within it. This means...
Read more >enum — Support for enumerations — Python 3.11.1 ...
The class Color is an enumeration (or enum) · The attributes Color.RED , Color.GREEN , etc., are enumeration members (or members) and are...
Read more >PHP 8.1: Enums
The UnitEnum::cases method returns an array of all cases of a given Enum. PHP classes are not allowed to implement this interface, and...
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
I’m not seeing anywhere in the project where basic scala Enumerations have a provided Encoder/Decoder instance. However, following how the json4s handled this I came up with the following
Yes, we’d want them to be in the companion objects so that they get made available without additional imports. Thanks, @mariussoutier!