Skip to content

Commit

Permalink
Fixed JsObject, JsArray to string
Browse files Browse the repository at this point in the history
  • Loading branch information
chungonn committed Jul 6, 2024
1 parent 07916b3 commit 7e09c74
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name := "commons-json"

organization := "com.greenfossil"

version := "1.0.13"
version := "1.0.14-RC1"

scalaVersion := "3.3.3"

Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/com/greenfossil/commons/json/JsValue.scala
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,8 @@ sealed trait JsValue extends Dynamic:
case JsTemporal(value, format, zoneId) => value.toString
case JsBoolean(value) => value.toString
case JsNull => null
case JsObject(value) => value.toString
case JsArray(value) => value.toString
case JsObject(value) => jsValue.stringify
case JsArray(value) => jsValue.stringify
case JsUndefined(value) => throw new JsonException(s"Undefined value [${value}]")

private def jsValueToNumber(jsValue: JsValue, tpe: String): Number =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,21 @@ class JsonAsDeserializedSuite extends munit.FunSuite {
assertEquals((jsonObj \"parent" \ "age").asOpt[Int], None) //parent field is missing
}

test("as[String] for JsValue should stringify"){
val string = """{
| "identifier" : [ {
| "system" : {
| "value" : "system 1"
| },
| "value" : {
| "value" : "a value"
| }
| } ]
|}""".stripMargin

val id= Json.parse(string).identifier.as[Seq[JsValue]].head
assertEquals(id.system.as[String], """{"value":"system 1"}""")
assertEquals(id.$value.as[String], """{"value":"a value"}""")
}

}

0 comments on commit 7e09c74

Please sign in to comment.