-
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 branch 'refs/heads/release/1.18' into NU-1890-hide-categories-w…
…hen-there-is-only-one-category-available # Conflicts: # designer/client/src/components/toolbars/scenarioDetails/CategoryDetails.tsx # docs/Changelog.md
- Loading branch information
Showing
33 changed files
with
279 additions
and
108 deletions.
There are no files selected for viewing
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 | ||
) | ||
|
||
} |
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
21 changes: 21 additions & 0 deletions
21
components-api/src/test/scala/pl/touk/nussknacker/engine/api/json/FromJsonDecoderTest.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,21 @@ | ||
package pl.touk.nussknacker.engine.api.json | ||
|
||
import io.circe.Json | ||
import org.scalatest.OptionValues | ||
import org.scalatest.funsuite.AnyFunSuiteLike | ||
import org.scalatest.matchers.should.Matchers | ||
|
||
class FromJsonDecoderTest extends AnyFunSuiteLike with Matchers with OptionValues { | ||
|
||
test("json number decoding pick the narrowest type") { | ||
FromJsonDecoder.jsonToAny(Json.fromInt(1)) shouldBe 1 | ||
FromJsonDecoder.jsonToAny(Json.fromInt(Integer.MAX_VALUE)) shouldBe Integer.MAX_VALUE | ||
FromJsonDecoder.jsonToAny(Json.fromLong(Long.MaxValue)) shouldBe Long.MaxValue | ||
FromJsonDecoder.jsonToAny( | ||
Json.fromBigDecimal(java.math.BigDecimal.valueOf(Double.MaxValue)) | ||
) shouldBe java.math.BigDecimal.valueOf(Double.MaxValue) | ||
val moreThanLongMaxValue = BigDecimal(Long.MaxValue) * 10 | ||
FromJsonDecoder.jsonToAny(Json.fromBigDecimal(moreThanLongMaxValue)) shouldBe moreThanLongMaxValue.bigDecimal | ||
} | ||
|
||
} |
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
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
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
Oops, something went wrong.