clj-commons/clj-yaml

Dump aliases

arichiardi opened this issue · 4 comments

Hi there again! I have a document with many aliases and I am wondering if I am missing a way to correctly dump aliases.

I have a object with something like this and I am manually trying to emit aliases but with this:

{:foo "*sharedFoo"}

I see this output:

foo: '*sharedFoo'

Do I need the apices around them? Is there a better way to do this?

lread commented

Hi @arichiardi, thanks for asking another question.

To be honest, I'm not sure, but we'll explore and learn.

Let' see what happens when we parse YAML with an anchor and alias:

(require '[clj-yaml.core :as yaml])

(yaml/parse-string "stuff:
  - foo: &namedthing
      bar: hey
      baz: there
  - other-foo: *namedthing")
;; => {:stuff
;;     ({:foo {:bar "hey", :baz "there"}} {:other-foo {:bar "hey", :baz "there"}})}

Ah. If I've understood your question, I see what you mean. The alias and anchor have been evaluated and processed-out by SnakeYAML during parsing.

Can you tell me more about specifically what you are trying to do?
Are you looking to somehow preserve anchors and aliases or just return a list of them?

Hi @lread thank you for trying things out and learn with me.

It all works on parse. The problem is on generate, where I am now sure how to represent/force aliasing.

As a workaround I am not post processing the yaml string but it feels...wrong 😃

I can dig into SnakeYAML no worries, will report back next week in case I find something.

lread commented

The problem is on generate, where I am not sure how to represent/force aliasing.

Ah, I think I understand now. You are trying to generate YAML that includes anchors and aliases? Interesting. I don't think clj-yaml currently explicitly supports that use case.

lread commented

It seems to me SnakeYAML was not designed to preserve the original YAML it reads.
It returns the result of reading and evaluating YAML.

So for now, I'm going to close this one. But please do re-open if you disagree or you've learned that my understanding is wrong.