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

Support for inline list rendering #37

Open
lyonssp opened this issue Jun 19, 2018 · 1 comment
Open

Support for inline list rendering #37

lyonssp opened this issue Jun 19, 2018 · 1 comment

Comments

@lyonssp
Copy link

lyonssp commented Jun 19, 2018

I want to serialize my yaml list inline, rather than producing to the more common multi-line rendering.

Want:

foo:
  list: [this, list, of, stuff]

Default:

foo:
  list:
  - this
  - list
  - of
  - stuff

It doesn't seem like this kind of serialization is documented, but I was wondering if it is supported at all.

More broadly, is there a way to hook into the printing process to dictate how YamlValue objects are rendered?

@MichelCarroll
Copy link

MichelCarroll commented Sep 30, 2020

Yes, you can explicitly use your own YamlPrinter instance to control the format. For your specific case, there's already a built-in option to output inline lists:

    val yaml = YamlArray(
      YamlString("a"),
      YamlString("b"),
      YamlString("c")
    )

    val printer = new SnakeYamlPrinter(flowStyle = Flow)

    yaml.print(printer) should === (
      """[a, b, c]
        |""".stripMargin)

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

2 participants