Skip to content

Commit

Permalink
scala-yaml 0.3.0 (#442)
Browse files Browse the repository at this point in the history
  • Loading branch information
sideeffffect authored Aug 1, 2024
1 parent 1c3ad13 commit 4faecc0
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 12 deletions.
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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?

Expand All @@ -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:
Expand Down
10 changes: 5 additions & 5 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
),
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -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")

0 comments on commit 4faecc0

Please sign in to comment.