diff --git a/README.md b/README.md index 0b2ff2e..561c34d 100644 --- a/README.md +++ b/README.md @@ -5,8 +5,10 @@ [![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.circe/circe-yaml_2.12/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.circe/circe-yaml_2.12) This is a small library for parsing [YAML](https://yaml.org) into [circe](https://github.com/circe/circe)'s `Json` AST. - * For parsing YAML 1.1 it uses [SnakeYAML](https://bitbucket.org/snakeyaml/snakeyaml). - * For parsing YAML 1.2 it uses [snakeyaml-engine](https://bitbucket.org/snakeyaml/snakeyaml-engine). +You can choose from multiple YAML backends: + * `circe-yaml`: For parsing YAML 1.1 it uses [SnakeYAML](https://bitbucket.org/snakeyaml/snakeyaml). + * `circe-yaml-v12`: For parsing YAML 1.2 it uses [snakeyaml-engine](https://bitbucket.org/snakeyaml/snakeyaml-engine). + * `circe-yaml-scalayaml`: For parsing YAML on Scala.js or Scala Native (as well as Scala/JVM) it uses [scala-yaml](https://github.com/VirtusLab/scala-yaml). ## Why? @@ -24,11 +26,15 @@ The artifact is hosted by Sonatype, and release versions are synced to Maven Cen For YAML 1.1 ```scala -libraryDependencies += "io.circe" %% "circe-yaml" % "0.14.2" +libraryDependencies += "io.circe" %% "circe-yaml" % "0.16.0" ``` or for YAML 1.2 ```scala -libraryDependencies += "io.circe" %% "circe-yaml-v12" % "0.14.2" +libraryDependencies += "io.circe" %% "circe-yaml-v12" % "0.16.0" +``` +or for YAML on Scala.js or Scala Native (as well as Scala/JVM) +```scala +libraryDependencies += "io.circe" %% "circe-yaml-scalayaml" % "0.16.0" ``` Snapshot versions are available by adding the Sonatype Snapshots resolver: diff --git a/build.sbt b/build.sbt index c123b0f..b8e5ec2 100644 --- a/build.sbt +++ b/build.sbt @@ -1,4 +1,4 @@ -ThisBuild / tlBaseVersion := "0.15" +ThisBuild / tlBaseVersion := "0.16" ThisBuild / circeRootOfCodeCoverage := None ThisBuild / startYear := Some(2016) ThisBuild / tlFatalWarnings := false //TODO: ... fix this someday @@ -33,7 +33,7 @@ val root = tlCrossRootProject.aggregate( lazy val `circe-yaml-common` = crossProject(JSPlatform, JVMPlatform, NativePlatform) .in(file("circe-yaml-common")) .settings( - description := "Library for converting between SnakeYAML's AST (YAML 2.0) and circe's AST", + description := "Common interface for circe-yaml.", libraryDependencies ++= Seq( "io.circe" %%% "circe-core" % Versions.circe ), @@ -44,7 +44,7 @@ lazy val `circe-yaml` = project .in(file("circe-yaml")) .dependsOn(`circe-yaml-common`.jvm) .settings( - description := "Library for converting between SnakeYAML's AST (YAML 2.0) and circe's AST", + description := "Library for converting between SnakeYAML's AST (YAML 1.1) and circe's AST", libraryDependencies ++= Seq( "org.yaml" % "snakeyaml" % Versions.snakeYaml, "io.circe" %% "circe-jawn" % Versions.circe % Test, @@ -61,7 +61,7 @@ lazy val `circe-yaml-v12` = project .in(file("circe-yaml-v12")) .dependsOn(`circe-yaml-common`.jvm) .settings( - description := "Library for converting between snakeyaml-engine's AST (YAML 2.0) and circe's AST", + description := "Library for converting between snakeyaml-engine's AST (YAML 1.2) and circe's AST", libraryDependencies ++= Seq( "io.circe" %% "circe-jawn" % Versions.circe % Test, "org.snakeyaml" % "snakeyaml-engine" % Versions.snakeYamlEngine, @@ -79,7 +79,7 @@ lazy val `circe-yaml-scalayaml` = crossProject(JSPlatform, JVMPlatform, NativePl .settings( description := "Library for converting between scala-yaml AST and circe's AST", libraryDependencies ++= Seq( - "org.virtuslab" %%% "scala-yaml" % "0.1.0", + "org.virtuslab" %%% "scala-yaml" % "0.3.0", "org.scalatest" %%% "scalatest" % Versions.scalaTest % Test ), tlVersionIntroduced := List("2.13", "3").map(_ -> "0.15.3").toMap diff --git a/circe-yaml-scalayaml/shared/src/main/scala/io/circe/yaml/scalayaml/Printer.scala b/circe-yaml-scalayaml/shared/src/main/scala/io/circe/yaml/scalayaml/Printer.scala index fdb7d73..987c7cf 100644 --- a/circe-yaml-scalayaml/shared/src/main/scala/io/circe/yaml/scalayaml/Printer.scala +++ b/circe-yaml-scalayaml/shared/src/main/scala/io/circe/yaml/scalayaml/Printer.scala @@ -20,6 +20,8 @@ import io.circe.Json import org.virtuslab.yaml.Node import org.virtuslab.yaml.NodeOps +import scala.collection.immutable.ListMap + object Printer extends io.circe.yaml.common.Printer { override def pretty(json: Json): String = { @@ -31,7 +33,8 @@ object Printer extends io.circe.yaml.common.Printer { case Json.JArray(value) => Node.SequenceNode(value.map(jsonToNode): _*) case Json.JObject(value) => - Node.MappingNode(value.toMap.map { case (key, value) => (Node.ScalarNode(key): Node) -> jsonToNode(value) }) + val mappings = value.toList.map { case (key, value) => (Node.ScalarNode(key): Node) -> jsonToNode(value) } + Node.MappingNode(ListMap.from(mappings)) case json => Node.ScalarNode(json.toString) } diff --git a/circe-yaml-scalayaml/shared/src/test/scala/io/circe/yaml/scalayaml/PrinterTests.scala b/circe-yaml-scalayaml/shared/src/test/scala/io/circe/yaml/scalayaml/PrinterTests.scala index ccbd027..ceef0fa 100644 --- a/circe-yaml-scalayaml/shared/src/test/scala/io/circe/yaml/scalayaml/PrinterTests.scala +++ b/circe-yaml-scalayaml/shared/src/test/scala/io/circe/yaml/scalayaml/PrinterTests.scala @@ -75,7 +75,7 @@ class PrinterTests extends AnyFreeSpec with Matchers { "Drop null keys" in { val json = Json.obj("nullField" -> Json.Null, "nonNullField" -> Json.fromString("foo")) - Printer.pretty(json) shouldEqual "nullField: null\nnonNullField: \"foo\"\n" + Printer.pretty(json) shouldEqual "nullField: !!null\nnonNullField: \"foo\"\n" } "Root integer" in { diff --git a/project/plugins.sbt b/project/plugins.sbt index 6bc7411..c36c46c 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,4 +1,4 @@ addSbtPlugin("io.circe" % "sbt-circe-org" % "0.4.1") -addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.5.2") +addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.5.4") addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.16.0") addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.12.1")