Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scala-yaml 0.3.0 #442

Merged
merged 4 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.15.4"
```
or for YAML 1.2
```scala
libraryDependencies += "io.circe" %% "circe-yaml-v12" % "0.14.2"
libraryDependencies += "io.circe" %% "circe-yaml-v12" % "0.15.4"
```
or for YAML on Scala.js or Scala Native (as well as Scala/JVM)
```scala
libraryDependencies += "io.circe" %% "circe-yaml-scalayaml" % "0.15.4"
```

Snapshot versions are available by adding the Sonatype Snapshots resolver:
Expand Down
8 changes: 4 additions & 4 deletions build.sbt
Original file line number Diff line number Diff line change
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",
sideeffffect marked this conversation as resolved.
Show resolved Hide resolved
"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")