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

enum yamlcodec fails roundtrip test #363

Open
lbialy opened this issue Nov 22, 2024 · 0 comments
Open

enum yamlcodec fails roundtrip test #363

lbialy opened this issue Nov 22, 2024 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@lbialy
Copy link
Contributor

lbialy commented Nov 22, 2024

import org.virtuslab.yaml.*

enum Rule derives YamlCodec:
  case Allow(ip: String)
  case Deny(ip: String)
  case DenyAll
  case AllowAll
  
scala> List(Rule.Allow("192.168.0.1"), Rule.Deny("192.168.1.1")).asYaml.as[List[Rule]]
val res2: Either[org.virtuslab.yaml.YamlError, List[Rule]] = Right(List(Allow(192.168.0.1), Allow(192.168.1.1)))

scala> List(Rule.Allow("192.168.0.1"), Rule.Deny("192.168.1.1"), Rule.DenyAll).asYaml.as[List[Rule]]
val res3: Either[org.virtuslab.yaml.YamlError, List[Rule]] = Left(org.virtuslab.yaml.ConstructError: Cannot parse ScalarNode(,CoreSchemaTag(tag:yaml.org,2002:null),Some(Range(Position(45,5,0),Vector(- ,   ip: 192.168.0.1, - ,   ip: 192.168.1.1, - , ),None)))
at 5:0,

^ )

I think encoding of enums is plain broken as it seems to loose discriminator information:

scala> List(Rule.Allow("192.168.0.1"), Rule.Deny("192.168.1.1"), Rule.DenyAll).asYaml
val res4: String = "-
  ip: 192.168.0.1
-
  ip: 192.168.1.1
-
"
@lbialy lbialy added the bug Something isn't working label Nov 22, 2024
@lbialy lbialy self-assigned this Nov 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant