Skip to content

Instantly share code, notes, and snippets.

@fanf
Created August 22, 2023 09:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fanf/445e9228cd62bb786960ce2242c1020c to your computer and use it in GitHub Desktop.
Save fanf/445e9228cd62bb786960ce2242c1020c to your computer and use it in GitHub Desktop.
Bad encoding in ZIO Yaml
package test.yaml
import zio.json._
import zio.json.yaml._
// Default indentation seems broken in YAML.
// If we change zio.json.yaml.JsonOps to add `setIndentWithIndicator(true)` it seems to work
//
// dumperOptions.setLineBreak(options.lineBreak)
// + dumperOptions.setIndentWithIndicator(true)
object ZioYamlTest {
final case class Param(
id: String,
mandatory: Boolean
)
final case class Container(
id: String,
version: Int,
params: Seq[Param]
)
implicit val codecParam: JsonCodec[Param] = DeriveJsonCodec.gen
implicit val codecSimpleContainer: JsonCodec[Container] = DeriveJsonCodec.gen
def main(args: Array[String]): Unit = {
val c = Container("foo", 42, List(Param("p1", true)))
println(c.toYaml().getOrElse(throw new RuntimeException("oups")))
}
/*
** Result:
id: foo
version: 42
params:
-
id: p1
mandatory: true
** Expected:
id: foo
version: 42
params:
- id: p1
mandatory: true
*/
}
@fanf
Copy link
Author

fanf commented Aug 22, 2023

This will be corrected by version including zio/zio-json#1004

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment