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

Anchors and aliases don't seem to work as expected #358

Open
padhia opened this issue Oct 27, 2024 · 3 comments
Open

Anchors and aliases don't seem to work as expected #358

padhia opened this issue Oct 27, 2024 · 3 comments

Comments

@padhia
Copy link

padhia commented Oct 27, 2024

I'm not sure if I'm doing something wrong, but the following snippet includes a valid YAML document that fails to decode.

import org.virtuslab.yaml.*

val doc =
  """|a1: &a
     |  x: 1
     |  y: 2
     |a2:
     |  <<: *a
     |  y: 3""".stripMargin

case class A(x: Int, y: Int) derives YamlDecoder

assert(doc.as[Map[String, A]].isRight)

Any suggestions to get the above example to parse correctly?

Thanks

@tgodzik
Copy link
Member

tgodzik commented Oct 28, 2024

@lbialy do you know is this currently supported actually?

@lbialy
Copy link
Contributor

lbialy commented Oct 28, 2024

I think references aren't implemented, unfortunately. What error do you get here @padhia?

@padhia
Copy link
Author

padhia commented Oct 28, 2024

Thanks for the quick response. The error I get is,

Key x doesn't exist in parsed document at 5:2,
  y:3
  ^

It seems << is treated as a regular YAML mapping object key. Thus, to instantiate an object of class A, << "key" is being silently ignored because it's not required, and the remaining key, that is y, is not sufficient because x is "missing".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants