Skip to content

Commit

Permalink
Override Json.Bool.apply (#1291)
Browse files Browse the repository at this point in the history
  • Loading branch information
plokhotnyuk authored Feb 6, 2025
1 parent 049508a commit 6446a1c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 6 additions & 2 deletions zio-json/shared/src/main/scala/zio/json/ast/ast.scala
Original file line number Diff line number Diff line change
Expand Up @@ -466,8 +466,12 @@ object Json {
}

object Bool {
val False: Bool = Bool(false)
val True: Bool = Bool(true)
val False: Bool = new Bool(false)
val True: Bool = new Bool(true)

def apply(value: Boolean): Bool =
if (value) True
else False

implicit val decoder: JsonDecoder[Bool] = new JsonDecoder[Bool] {
def unsafeDecode(trace: List[JsonError], in: RetractReader): Bool =
Expand Down
4 changes: 4 additions & 0 deletions zio-json/shared/src/test/scala/zio/json/ast/JsonSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ object JsonSpec extends ZIOSpecDefault {
val spec: Spec[Environment, Any] =
suite("Json")(
suite("apply")(
test("Bool()") {
assertTrue(Json.Bool.True eq Json.Bool(true)) &&
assertTrue(Json.Bool.False eq Json.Bool(false))
},
test("()") {
assertTrue(Json.Obj.empty eq Json()) &&
assertTrue(Json.Obj.empty eq Json.Obj()) &&
Expand Down

0 comments on commit 6446a1c

Please sign in to comment.