Created
August 22, 2023 09:37
-
-
Save fanf/445e9228cd62bb786960ce2242c1020c to your computer and use it in GitHub Desktop.
Bad encoding in ZIO Yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
*/ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This will be corrected by version including zio/zio-json#1004