diff --git a/ballerina/Ballerina.toml b/ballerina/Ballerina.toml index 4dd2f27..eef8f5c 100644 --- a/ballerina/Ballerina.toml +++ b/ballerina/Ballerina.toml @@ -1,16 +1,16 @@ [package] org = "ballerina" name = "constraint" -version = "1.1.1" +version = "1.2.0" authors = ["Ballerina"] keywords = ["constraint", "validation"] repository = "https://github.com/ballerina-platform/module-ballerina-constraint" icon = "icon.png" license = ["Apache-2.0"] -distribution = "2201.4.0" +distribution = "2201.5.0" [[platform.java11.dependency]] groupId = "io.ballerina.stdlib" artifactId = "constraint-native" -version = "1.1.1" -path = "../native/build/libs/constraint-native-1.1.1-SNAPSHOT.jar" +version = "1.2.0" +path = "../native/build/libs/constraint-native-1.2.0-SNAPSHOT.jar" diff --git a/ballerina/CompilerPlugin.toml b/ballerina/CompilerPlugin.toml index 66f9ea7..db4b8b4 100644 --- a/ballerina/CompilerPlugin.toml +++ b/ballerina/CompilerPlugin.toml @@ -3,4 +3,4 @@ id = "constraint-compiler-plugin" class = "io.ballerina.stdlib.constraint.compiler.ConstraintCompilerPlugin" [[dependency]] -path = "../compiler-plugin/build/libs/constraint-compiler-plugin-1.1.1-SNAPSHOT.jar" +path = "../compiler-plugin/build/libs/constraint-compiler-plugin-1.2.0-SNAPSHOT.jar" diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index ac24498..badd2bc 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -5,11 +5,12 @@ [ballerina] dependencies-toml-version = "2" +distribution-version = "2201.5.0" [[package]] org = "ballerina" name = "constraint" -version = "1.1.1" +version = "1.2.0" dependencies = [ {org = "ballerina", name = "jballerina.java"}, {org = "ballerina", name = "test"}, diff --git a/build-config/resources/Ballerina.toml b/build-config/resources/Ballerina.toml index 8e00527..a6f0637 100644 --- a/build-config/resources/Ballerina.toml +++ b/build-config/resources/Ballerina.toml @@ -7,7 +7,7 @@ keywords = ["constraint", "validation"] repository = "https://github.com/ballerina-platform/module-ballerina-constraint" icon = "icon.png" license = ["Apache-2.0"] -distribution = "2201.4.0" +distribution = "2201.5.0" [[platform.java11.dependency]] groupId = "io.ballerina.stdlib" diff --git a/changelog.md b/changelog.md index 53ad63c..8185608 100644 --- a/changelog.md +++ b/changelog.md @@ -10,6 +10,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), - [Introduce `@constriant:Date` to validate date structures](https://github.com/ballerina-platform/ballerina-standard-library/issues/3960) - [Allow constraints on subtypes](https://github.com/ballerina-platform/ballerina-standard-library/issues/4349) +### Changed +- [Use `ValueUtils.convert` API instead of `CloneWithType` method](https://github.com/ballerina-platform/ballerina-standard-library/issues/3933) + ## [1.1.0] - 2023-02-20 ### Fixed diff --git a/gradle.properties b/gradle.properties index 4216e29..34701b7 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,13 +1,13 @@ org.gradle.caching=true group=io.ballerina.stdlib -version=1.1.1-SNAPSHOT +version=1.2.0-SNAPSHOT puppycrawlCheckstyleVersion=8.18 slf4jVersion=1.7.30 testngVersion=7.4.0 ballerinaGradlePluginVersion=1.0.3 jacocoVersion=0.8.8 -ballerinaLangVersion=2201.4.0 +ballerinaLangVersion=2201.5.0 # Test dependency stdlibTimeVersion=2.2.4 diff --git a/native/src/main/java/io/ballerina/stdlib/constraint/Constraints.java b/native/src/main/java/io/ballerina/stdlib/constraint/Constraints.java index ac9c29c..cc2c5c9 100644 --- a/native/src/main/java/io/ballerina/stdlib/constraint/Constraints.java +++ b/native/src/main/java/io/ballerina/stdlib/constraint/Constraints.java @@ -26,6 +26,7 @@ import io.ballerina.runtime.api.types.Type; import io.ballerina.runtime.api.types.UnionType; import io.ballerina.runtime.api.utils.TypeUtils; +import io.ballerina.runtime.api.utils.ValueUtils; import io.ballerina.runtime.api.values.BArray; import io.ballerina.runtime.api.values.BError; import io.ballerina.runtime.api.values.BMap; @@ -33,7 +34,6 @@ import io.ballerina.stdlib.constraint.annotations.AbstractAnnotations; import io.ballerina.stdlib.constraint.annotations.RecordFieldAnnotations; import io.ballerina.stdlib.constraint.annotations.TypeAnnotations; -import org.ballerinalang.langlib.value.CloneWithType; import java.util.ArrayList; import java.util.List; @@ -49,12 +49,15 @@ public class Constraints { public static Object validate(Object value, BTypedesc typedesc) { + Type type = typedesc.getDescribingType(); + try { - Type type = typedesc.getDescribingType(); value = cloneWithTargetType(value, type); - if (value instanceof BError) { - return ErrorUtils.buildTypeConversionError((BError) value); - } + } catch (BError e) { + return ErrorUtils.buildTypeConversionError(e); + } + + try { List failedConstraints = validateAfterTypeConversionInternal(value, type, SYMBOL_DOLLAR_SIGN); if (!failedConstraints.isEmpty()) { return ErrorUtils.buildValidationError(failedConstraints); @@ -161,10 +164,8 @@ private static AbstractAnnotations getAnnotationImpl(Type type, List fai } private static Object cloneWithTargetType(Object value, Type targetType) { - if (!TypeUtils.isSameType(TypeUtils.getType(value), targetType)) { - value = CloneWithType.convert(targetType, value); - } - return value; + return TypeUtils.isSameType(TypeUtils.getType(value), targetType) ? value + : ValueUtils.convert(value, targetType); } private Constraints() {