Skip to content

Commit

Permalink
Fix return value of std.parseYaml for primitive yaml types
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenamar-db committed Dec 29, 2024
1 parent 6f4e54b commit 2df1a92
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions sjsonnet/src-jvm/sjsonnet/Platform.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ object Platform {
}

/**
* Valid compression levels are 0 (no compression) to 9 (maximum compression).
* Valid compression levels are 0 (no compression) to 9 (maximum compression).
*/
def xzBytes(b: Array[Byte], compressionLevel: Option[Int]): String = {
val outputStream: ByteArrayOutputStream = new ByteArrayOutputStream(b.length)
Expand All @@ -51,14 +51,14 @@ object Platform {

def yamlToJson(yamlString: String): String = {
try {
val yaml = new Yaml(new SafeConstructor(new LoaderOptions())).loadAll(yamlString)
.asInstanceOf[java.lang.Iterable[java.util.Collection[Object]]].asScala.toSeq
val yaml = new Yaml(new SafeConstructor(new LoaderOptions())).loadAll(yamlString).asScala.toSeq
yaml.size match {
case 0 => "{}"
case 1 if yaml.head.isInstanceOf[java.util.Map[String, Object]] =>
new JSONObject(yaml.head.asInstanceOf[java.util.Map[String, Object]]).toString()
case 1 if yaml.head.isInstanceOf[java.util.List[Object]] =>
new JSONArray(yaml.head.asInstanceOf[java.util.List[Object]]).toString()
case 1 => yaml.head match {
case m: java.util.Map[_, _] => new JSONObject(m).toString()
case l: java.util.List[_] => new JSONArray(l).toString()
case _ => new JSONArray(yaml.asJava).get(0).toString
}
case _ => new JSONArray(yaml.asJava).toString()
}
} catch {
Expand All @@ -70,7 +70,7 @@ object Platform {
private def computeHash(algorithm: String, s: String) = {
java.security.MessageDigest.getInstance(algorithm)
.digest(s.getBytes("UTF-8"))
.map{ b => String.format("%02x", (b & 0xff).asInstanceOf[Integer])}
.map { b => String.format("%02x", (b & 0xff).asInstanceOf[Integer]) }
.mkString
}

Expand Down

0 comments on commit 2df1a92

Please sign in to comment.