Writing Scala 3 enums is broken
See original GitHub issueTrying to write Scala 3 enum
values actually writes always the first one.
Test reproducing the problem
package upickle
import scala.language.implicitConversions
import utest._
import upickle.default._
object EnumTests extends TestSuite {
enum SimpleEnum {
case A, B
}
val tests = Tests {
test("simple") {
given ReadWriter[SimpleEnum] = macroRW[SimpleEnum]
test("enum write") {
val parsed = write(SimpleEnum.B)
val expected = """{"$type":"upickle.EnumTests.SimpleEnum.B"}"""
assert(parsed == expected)
}
}
}
}
Fails with:
X upickle.EnumTests.simple.enum write 71ms
utest.AssertionError: parsed == expected
parsed: String = {"$type":"upickle.EnumTests.SimpleEnum.A"}
expected: String = {"$type":"upickle.EnumTests.SimpleEnum.B"}
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:13 (7 by maintainers)
Top Results From Across the Web
An example of using enums in Scala 3 (Dotty) - Alvin Alexander
Here's a quick example of how to use Scala 3 enums, including using them as constructor and method parameters, and in a match...
Read more >Enumerations
An enumeration is used to define a type consisting of a set of named values. ... This defines a new sealed class, Color...
Read more >(De)serialize enum as string in Scala 3 - Stack Overflow
I am trying to find a simple and efficient way to (de)serialize enums in Scala 3 using circe . Consider the following example:...
Read more >Learn How Enum Function Work in Scala? - eduCBA
3 ) Scala enum hierarchy;. Serializable; Enumeration; RoundingMode. Below is one example which will explain its working; what we are doing here is...
Read more >Enums in Scala 3 - Rock the JVM Blog
This article is for Scala programmers of all levels, and particularly for those Scala programmers who have been emulating enums in Scala 2...
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 Free
Top 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
There might be something useful that can be ported over from https://github.com/rallyhealth/weePickle/pull/94.
Looks like ADTs encoded using enums also fail.
Using the
Color
example in https://docs.scala-lang.org/scala3/reference/enums/adts.htmlFails with