-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Benjamin Voiturier <benjamin.voiturier@iohk.io>
- Loading branch information
1 parent
e0ac2f4
commit c780920
Showing
6 changed files
with
38 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 12 additions & 12 deletions
24
shared/json/src/main/scala/org/hyperledger/identus/shared/json/JsonOps.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,21 @@ | ||
package org.hyperledger.identus.shared.json | ||
|
||
import zio.json.ast.Json as ZioJson | ||
import zio.json.ast.Json | ||
|
||
object JsonOps { | ||
extension (json: ZioJson) { | ||
def removeNullValues: ZioJson = json match | ||
case ZioJson.Obj(fields) => | ||
ZioJson.Obj(fields.collect { case (key, value) if value != ZioJson.Null => key -> value.removeNullValues }) | ||
case ZioJson.Arr(elements) => | ||
ZioJson.Arr(elements.map(_.removeNullValues)) | ||
extension (json: Json) { | ||
def removeNullValues: Json = json match | ||
case Json.Obj(fields) => | ||
Json.Obj(fields.collect { case (key, value) if value != Json.Null => key -> value.removeNullValues }) | ||
case Json.Arr(elements) => | ||
Json.Arr(elements.map(_.removeNullValues)) | ||
case other => other | ||
|
||
def removeField(name: String): ZioJson = json match | ||
case ZioJson.Obj(fields) => | ||
ZioJson.Obj(fields.filterNot { case (key, value) => key == name }) | ||
case ZioJson.Arr(elements) => | ||
ZioJson.Arr(elements.map(_.removeField(name))) | ||
def removeField(name: String): Json = json match | ||
case Json.Obj(fields) => | ||
Json.Obj(fields.filterNot { case (key, value) => key == name }) | ||
case Json.Arr(elements) => | ||
Json.Arr(elements.map(_.removeField(name))) | ||
case other => other | ||
} | ||
} |