vendredi 29 mai 2015

SnakeYaml: handling multiline strings

I'm trying to use snakeYaml to save multiline strings (code snippets) in human-readable form. My scala code:

val code ="""// test
      |println("Hello world!")
      |exit(1)
    """.stripMargin

  val map: java.util.Map[String, String] = new java.util.HashMap[String, String]()
  map.put("Code", code)
  System.out.println(code)

  val options = new DumperOptions()
  options.setDefaultScalarStyle(ScalarStyle.PLAIN)

  val yamal = new Yaml(options)

  System.out.println(yamal.dump(map))

produces yaml:

Code: "// test\r\nprintln(\"Hello world!\")\r\nexit(1)\r\n\r\n        "

but should produce something like below. Playing with different options didn't help so far.

Code: | 
// test
println("Hello world!")
exit(1)

Aucun commentaire:

Enregistrer un commentaire