-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/staging' into optimize-periodic-…
…deployment-manger-db-queries
- Loading branch information
Showing
314 changed files
with
5,317 additions
and
2,508 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
25 changes: 25 additions & 0 deletions
25
components-api/src/main/scala/pl/touk/nussknacker/engine/api/json/FromJsonDecoder.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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package pl.touk.nussknacker.engine.api.json | ||
|
||
import io.circe.Json | ||
import pl.touk.nussknacker.engine.util.Implicits._ | ||
|
||
import scala.jdk.CollectionConverters._ | ||
|
||
object FromJsonDecoder { | ||
|
||
def jsonToAny(json: Json): Any = json.fold( | ||
jsonNull = null, | ||
jsonBoolean = identity[Boolean], | ||
jsonNumber = jsonNumber => | ||
// we pick the narrowest type as possible to reduce the amount of memory and computations overheads | ||
jsonNumber.toInt orElse | ||
jsonNumber.toLong orElse | ||
// We prefer java big decimal over float/double | ||
jsonNumber.toBigDecimal.map(_.bigDecimal) | ||
getOrElse (throw new IllegalArgumentException(s"Not supported json number: $jsonNumber")), | ||
jsonString = identity[String], | ||
jsonArray = _.map(jsonToAny).asJava, | ||
jsonObject = _.toMap.mapValuesNow(jsonToAny).asJava | ||
) | ||
|
||
} |
Oops, something went wrong.