Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add read functionality with Jsonpath expressions for Ballerina json datatypes #1

Merged
merged 29 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
ffdbb7c
Add read functionality with Jsonpath expressions
SasinduDilshara Jan 29, 2024
2dcbe50
Add formatting changes for gradle properties file
SasinduDilshara Jan 29, 2024
2a6221f
Add jsonpath expression tests for append operation
SasinduDilshara Jan 30, 2024
44e5a36
Update license headers in ballerna and native files
SasinduDilshara Jan 31, 2024
16738cb
Update native package path&remove mapping provider
SasinduDilshara Jan 31, 2024
75bd1d5
Update Javadoc comment in Utils file
SasinduDilshara Jan 31, 2024
9c343ff
Merge branch 'main' of https://github.com/ballerina-platform/module-b…
SasinduDilshara Mar 21, 2024
c5220cf
[Automated] Update the native jar versions
SasinduDilshara Mar 21, 2024
5e9ebe9
[Automated] Update the native jar versions
SasinduDilshara Mar 21, 2024
80e2a07
[Automated] Update the native jar versions
SasinduDilshara Mar 21, 2024
06a93e3
[Automated] Update the native jar versions
SasinduDilshara Mar 21, 2024
cb140d3
[Automated] Update the native jar versions
SasinduDilshara Mar 21, 2024
4a0ab9a
Add gradle configurations for jsonpath operation
SasinduDilshara Mar 21, 2024
8613a90
Optimize for loops with array stream in jsonpath
SasinduDilshara Mar 21, 2024
2afcb74
Remove unused imports in BJsonPathProvider
SasinduDilshara Mar 21, 2024
6014e2f
Add code to pull external jars from maven
SasinduDilshara Mar 21, 2024
a47efa1
[Automated] Update the native jar versions
SasinduDilshara Mar 22, 2024
7fbe262
[Automated] Update the native jar versions
SasinduDilshara Mar 22, 2024
0bad58e
[Automated] Update the native jar versions
SasinduDilshara Mar 22, 2024
950b32a
[Automated] Update the native jar versions
SasinduDilshara Mar 22, 2024
845a854
[Automated] Update the native jar versions
SasinduDilshara Mar 22, 2024
6ed0c9a
Add sample examples for read function
SasinduDilshara Mar 22, 2024
75463f1
Remove vscode file
SasinduDilshara Mar 22, 2024
56dc93b
Merge branch 'main' of https://github.com/ballerina-platform/module-b…
SasinduDilshara Mar 25, 2024
4d42060
Add Graalvm properties json file
SasinduDilshara Mar 25, 2024
4aa2ef8
[Automated] Update the native jar versions
SasinduDilshara Mar 26, 2024
4f3b6d5
[Automated] Update the native jar versions
SasinduDilshara Mar 26, 2024
b4cce5c
Update string type conversions in lists
SasinduDilshara Mar 27, 2024
81e9642
Update doc comments and Ballerina tomls
SasinduDilshara Apr 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*.zip
*.tar.gz
*.rar
bin

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
Expand Down
25 changes: 22 additions & 3 deletions ballerina/Ballerina.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ org = "ballerina"
name = "data.jsondata"
version = "0.1.0"
authors = ["Ballerina"]
keywords = ["json"]
repository = "https://github.com/ballerina-platform/module-ballerina.jsondata"
keywords = ["json", "json path", "json-transform", "json transform", "json to json", "json-convert", "json convert"]
repository = "https://github.com/ballerina-platform/module-ballerina-data.jsondata"
license = ["Apache-2.0"]
distribution = "2201.8.4"
distribution = "2201.9.0-20240326-110600-aca0cc0c"
export = ["data.jsondata"]

[platform.java17]
graalvmCompatible = true
Expand All @@ -16,3 +17,21 @@ groupId = "io.ballerina.lib"
artifactId = "jsondata-native"
version = "0.1.0"
path = "../native/build/libs/data.jsondata-native-0.1.0-SNAPSHOT.jar"

[[platform.java17.dependency]]
path = "./lib/json-path-2.9.0.jar"
groupId = "com.jayway.jsonpath"
artifactId = "json-path"
version = "2.9.0"

[[platform.java17.dependency]]
path = "./lib/json-smart-2.4.7.jar"
groupId = "net.minidev.json"
artifactId = "json-smart"
version = "2.4.7"

[[platform.java17.dependency]]
path = "./lib/accessors-smart-2.4.7.jar"
groupId = "net.minidev.json"
artifactId = "accessors-smart"
version = "2.4.7"
60 changes: 59 additions & 1 deletion ballerina/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

[ballerina]
dependencies-toml-version = "2"
distribution-version = "2201.8.4"
distribution-version = "2201.9.0-20240326-110600-aca0cc0c"

[[package]]
org = "ballerina"
Expand All @@ -14,6 +14,9 @@ version = "0.1.0"
dependencies = [
{org = "ballerina", name = "io"},
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "lang.float"},
{org = "ballerina", name = "lang.int"},
{org = "ballerina", name = "lang.object"},
{org = "ballerina", name = "test"}
]
modules = [
Expand Down Expand Up @@ -41,6 +44,26 @@ modules = [
{org = "ballerina", packageName = "jballerina.java", moduleName = "jballerina.java"}
]

[[package]]
org = "ballerina"
name = "lang.__internal"
version = "0.0.0"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "lang.object"}
]

[[package]]
org = "ballerina"
name = "lang.array"
version = "0.0.0"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "lang.__internal"}
]

[[package]]
org = "ballerina"
name = "lang.error"
Expand All @@ -50,6 +73,40 @@ dependencies = [
{org = "ballerina", name = "jballerina.java"}
]

[[package]]
org = "ballerina"
name = "lang.float"
version = "0.0.0"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "jballerina.java"}
]
modules = [
{org = "ballerina", packageName = "lang.float", moduleName = "lang.float"}
]

[[package]]
org = "ballerina"
name = "lang.int"
version = "0.0.0"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "lang.__internal"},
{org = "ballerina", name = "lang.object"}
]
modules = [
{org = "ballerina", packageName = "lang.int", moduleName = "lang.int"}
]

[[package]]
org = "ballerina"
name = "lang.object"
version = "0.0.0"
modules = [
{org = "ballerina", packageName = "lang.object", moduleName = "lang.object"}
]

[[package]]
org = "ballerina"
name = "lang.value"
Expand All @@ -66,6 +123,7 @@ version = "0.0.0"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "lang.array"},
{org = "ballerina", name = "lang.error"}
]
modules = [
Expand Down
21 changes: 21 additions & 0 deletions ballerina/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,36 @@ def stripBallerinaExtensionVersion(String extVersion) {
apply plugin: 'io.ballerina.plugin'

ballerina {
testCoverageParam = "--code-coverage --coverage-format=xml --includes=io.ballerina.lib.data.*:ballerina.*"
packageOrganization = packageOrg
module = packageName
langVersion = ballerinaLangVersion
}

configurations {
externalJars
}

dependencies {

externalJars(group: 'com.jayway.jsonpath', name: 'json-path', version: "${javaJsonPathVersion}") {
transitive = false
}
externalJars(group: 'net.minidev', name: 'json-smart', version: "${javaJsonSmartVersion}") {
transitive = false
}
externalJars(group: 'net.minidev', name: 'accessors-smart', version: "${javaAccessorsSmartVersion}") {
transitive = false
}
}

task updateTomlFiles {
doLast {
def newConfig = ballerinaTomlFilePlaceHolder.text.replace("@project.version@", project.version)
newConfig = newConfig.replace("@toml.version@", tomlVersion)
newConfig = newConfig.replace("@jsonpath.version@", project.javaJsonPathVersion)
newConfig = newConfig.replace("@jsonsmart.version@", project.javaJsonSmartVersion)
newConfig = newConfig.replace("@accessors.version@", project.javaAccessorsSmartVersion)
ballerinaTomlFile.text = newConfig

def newCompilerPluginToml = compilerPluginTomlFilePlaceHolder.text.replace("@project.version@", project.version)
Expand Down
19 changes: 19 additions & 0 deletions ballerina/errors.bal
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com).
//
// WSO2 LLC. licenses this file to you under the Apache License,
// Version 2.0 (the "License"); you may not use this file except
// in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

# Represents the error type of the ballerina/data.jsondata module. This error type represents any error that can occur
# during the execution of jsondata APIs.
public type Error distinct error;
2 changes: 1 addition & 1 deletion ballerina/init.bal
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ isolated function init() {
}

isolated function setModule() = @java:Method {
'class: "io.ballerina.lib.data.jsondata.utils.ModuleUtils"
'class: "io.ballerina.lib.data.ModuleUtils"
} external;
4 changes: 0 additions & 4 deletions ballerina/json_api.bal
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,6 @@ public type Options record {|
boolean allowDataProjection = true;
|};

# Represents the error type of the ballerina/data.jsondata module. This error type represents any error that can occur
# during the execution of jsondata APIs.
public type Error distinct error;

# Defines the name of the JSON Object key.
#
# + value - The name of the JSON Object key
Expand Down
56 changes: 56 additions & 0 deletions ballerina/read.bal
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com).
//
// WSO2 LLC. licenses this file to you under the Apache License,
// Version 2.0 (the "License"); you may not use this file except
// in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

import ballerina/jballerina.java;
import ballerina/lang.'object as obj;

public type JsonPathValue json;

public type JsonPathRawTemplate object {
*obj:RawTemplate;
public string[] & readonly strings;
public JsonPathValue[] insertions;
};

# Extract details from the given JSON value using the provided query template expression.
#
# ```ballerina
# read({id: 1, "name": "John Doe"}, `$.name`) => "John Doe"
# ```
#
# + 'json - JSON value
# + query - JSON path expression
# + return - extracted details as JSON value, a jsonpath:Error otherwise
public isolated function read(json 'json, JsonPathRawTemplate query) returns json|Error {
SasinduDilshara marked this conversation as resolved.
Show resolved Hide resolved
return readJson('json, new JsonPathRawTemplateImpl(query));
}

class JsonPathRawTemplateImpl {
*JsonPathRawTemplate;

isolated function init(JsonPathRawTemplate jsonPathRawTemplate) {
self.strings = jsonPathRawTemplate.strings;
self.insertions = jsonPathRawTemplate.insertions;
}
}

# Extract details from the given JSON value using the provided query expression.
# + 'json - JSON value
# + query - JSON path expression
# + return - extracted details as JSON value, a jsonpath:Error otherwise
isolated function readJson(json 'json, JsonPathRawTemplateImpl query) returns json|Error = @java:Method {
'class: "io.ballerina.lib.data.jsonpath.BJsonPath"
} external;
Loading
Loading