-
Notifications
You must be signed in to change notification settings - Fork 36
Add backend changes to json/xml data conversion in data mapping #719
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
Merged
KavinduZoysa
merged 4 commits into
ballerina-platform:main
from
KavinduZoysa:fix-issue-2390
Feb 19, 2026
+1,825
−26
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
c29657a
Add backend changes to json/xml data mapping
KavinduZoysa f6a4c53
Merge branch 'main' of https://github.com/ballerina-platform/ballerin…
KavinduZoysa 2787b73
Handle sub mappings
KavinduZoysa 2efa114
Add few improvements to json/xml conversion
KavinduZoysa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
386 changes: 362 additions & 24 deletions
386
...del-generator-core/src/main/java/io/ballerina/flowmodelgenerator/core/DataMapManager.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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
36 changes: 36 additions & 0 deletions
36
.../java/io/ballerina/flowmodelgenerator/extension/request/DataMapperConvertTypeRequest.java
This file contains hidden or 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,36 @@ | ||
| /* | ||
| * Copyright (c) 2026, WSO2 LLC. (http://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. | ||
| */ | ||
|
|
||
| package io.ballerina.flowmodelgenerator.extension.request; | ||
|
|
||
| import com.google.gson.JsonElement; | ||
|
|
||
| /** | ||
| * Represents a request to convert an expression from one type to another for incompatible types. | ||
| * | ||
| * @param filePath The file path of the source file | ||
| * @param codedata The details of the node | ||
| * @param typeName The converted type name | ||
| * @param variableName The converted variable name | ||
| * @param isInput The converted variable is input or output | ||
| * | ||
| * @since 2.0.0 | ||
| */ | ||
| public record DataMapperConvertTypeRequest(String filePath, JsonElement codedata, String typeName, | ||
| String variableName, boolean isInput) { | ||
| } |
155 changes: 155 additions & 0 deletions
155
...n/src/test/java/io/ballerina/flowmodelgenerator/extension/DataMappingConvertTypeTest.java
This file contains hidden or 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,155 @@ | ||
| /* | ||
| * Copyright (c) 2026, WSO2 LLC. (http://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. | ||
| */ | ||
|
|
||
| package io.ballerina.flowmodelgenerator.extension; | ||
|
|
||
| import com.google.gson.JsonElement; | ||
| import com.google.gson.JsonObject; | ||
| import com.google.gson.reflect.TypeToken; | ||
| import io.ballerina.flowmodelgenerator.extension.request.DataMapperConvertTypeRequest; | ||
| import io.ballerina.modelgenerator.commons.AbstractLSTest; | ||
| import org.eclipse.lsp4j.TextEdit; | ||
| import org.testng.Assert; | ||
| import org.testng.annotations.DataProvider; | ||
| import org.testng.annotations.Test; | ||
|
|
||
| import java.io.IOException; | ||
| import java.lang.reflect.Type; | ||
| import java.nio.file.Files; | ||
| import java.nio.file.Path; | ||
| import java.nio.file.Paths; | ||
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| /** | ||
| * Tests for the generation of type conversion in data mapper. | ||
| * | ||
| * @since 2.0.0 | ||
| */ | ||
| public class DataMappingConvertTypeTest extends AbstractLSTest { | ||
|
|
||
| private static final Type textEditListType = new TypeToken<Map<String, List<TextEdit>>>() { | ||
| }.getType(); | ||
|
|
||
| @DataProvider(name = "data-provider") | ||
| @Override | ||
| protected Object[] getConfigsList() { | ||
| return new Object[][]{ | ||
| {Path.of("variable1.json")}, | ||
| {Path.of("variable2.json")}, | ||
| {Path.of("variable3.json")}, | ||
| {Path.of("variable4.json")}, | ||
| {Path.of("variable5.json")}, | ||
| {Path.of("variable6.json")}, | ||
| {Path.of("variable7.json")}, | ||
| {Path.of("variable8.json")}, | ||
| {Path.of("variable9.json")}, | ||
| {Path.of("variable10.json")}, | ||
| {Path.of("variable11.json")}, | ||
| {Path.of("variable12.json")}, | ||
| }; | ||
| } | ||
|
|
||
| @Override | ||
| @Test(dataProvider = "data-provider") | ||
| public void test(Path config) throws IOException { | ||
| Path configJsonPath = configDir.resolve(config); | ||
| TestConfig testConfig = gson.fromJson(Files.newBufferedReader(configJsonPath), TestConfig.class); | ||
|
|
||
| DataMapperConvertTypeRequest request = | ||
| new DataMapperConvertTypeRequest(sourceDir.resolve(testConfig.source()).toAbsolutePath().toString(), | ||
| testConfig.codedata(), testConfig.typeName(), testConfig.variableName(), | ||
| testConfig.isInput()); | ||
| JsonObject jsonMap = | ||
| getResponseAndCloseFile(request, testConfig.source()).getAsJsonObject("textEdits"); | ||
|
|
||
| Map<String, List<TextEdit>> actualTextEdits = gson.fromJson(jsonMap, textEditListType); | ||
|
|
||
| boolean assertFailure = false; | ||
|
|
||
| if (actualTextEdits.size() != testConfig.output().size()) { | ||
| log.info("The number of text edits does not match the expected output."); | ||
| assertFailure = true; | ||
| } | ||
|
|
||
| Map<String, List<TextEdit>> newMap = new HashMap<>(); | ||
| for (Map.Entry<String, List<TextEdit>> entry : actualTextEdits.entrySet()) { | ||
| Path fullPath = Paths.get(entry.getKey()); | ||
| String relativePath = sourceDir.relativize(fullPath).toString(); | ||
|
|
||
| List<TextEdit> textEdits = testConfig.output().get(relativePath.replace("\\", "/")); | ||
| if (textEdits == null) { | ||
| log.info("No text edits found for the file: " + relativePath); | ||
| assertFailure = true; | ||
| } else if (!assertArray("text edits", entry.getValue(), textEdits)) { | ||
| assertFailure = true; | ||
| } | ||
|
|
||
| newMap.put(relativePath, entry.getValue()); | ||
| } | ||
|
|
||
| if (assertFailure) { | ||
| TestConfig updatedConfig = new TestConfig(testConfig.source(), testConfig.description(), | ||
| testConfig.codedata(), testConfig.typeName(), testConfig.variableName(), testConfig.isInput(), | ||
| newMap); | ||
| // updateConfig(configJsonPath, updatedConfig); | ||
| Assert.fail(String.format("Failed test: '%s' (%s)", testConfig.description(), configJsonPath)); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| protected String getResourceDir() { | ||
| return "data_mapper_convert_type"; | ||
| } | ||
|
|
||
| @Override | ||
| protected Class<? extends AbstractLSTest> clazz() { | ||
| return DataMappingConvertTypeTest.class; | ||
| } | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| @Override | ||
| protected String getApiName() { | ||
| return "convertType"; | ||
| } | ||
|
|
||
| @Override | ||
| protected String getServiceName() { | ||
| return "dataMapper"; | ||
| } | ||
|
|
||
| /** | ||
| * Represents the test configuration for the type conversion tests. | ||
| * | ||
| * @param source The source file name | ||
| * @param description The description of the test | ||
| * @param codedata The Details of the node | ||
| * @param typeName The name of the converted type | ||
| * @param variableName The name of the converting variable | ||
| * @param isInput Whether the variable is an input variable or not | ||
| * @param output Generated source expression | ||
| */ | ||
| private record TestConfig(String source, String description, JsonElement codedata, | ||
| String typeName, String variableName, boolean isInput, | ||
| Map<String, List<TextEdit>> output) { | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| public String description() { | ||
| return description == null ? "" : description; | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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
40 changes: 40 additions & 0 deletions
40
...-generator-ls-extension/src/test/resources/data_mapper_convert_type/config/variable1.json
This file contains hidden or 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,40 @@ | ||
| { | ||
| "source": "variable1.bal", | ||
| "description": "Sample diagram node", | ||
| "codedata": { | ||
| "node": "VARIABLE", | ||
| "lineRange": { | ||
| "fileName": "main.bal", | ||
| "startLine": { | ||
| "line": 14, | ||
| "offset": 0 | ||
| }, | ||
| "endLine": { | ||
| "line": 16, | ||
| "offset": 2 | ||
| } | ||
| }, | ||
| "isNew": true, | ||
| "sourceCode": "" | ||
| }, | ||
| "typeName": "UserInfo", | ||
| "variableName": "user", | ||
| "isInput": true, | ||
| "output": { | ||
| "variable1.bal": [ | ||
| { | ||
| "range": { | ||
| "start": { | ||
| "line": 14, | ||
| "character": 67 | ||
| }, | ||
| "end": { | ||
| "line": 16, | ||
| "character": 1 | ||
| } | ||
| }, | ||
| "newText": "let UserInfo userConverted = check user.ensureType() in {\n\n}" | ||
| } | ||
| ] | ||
| } | ||
| } |
40 changes: 40 additions & 0 deletions
40
...generator-ls-extension/src/test/resources/data_mapper_convert_type/config/variable10.json
This file contains hidden or 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,40 @@ | ||
| { | ||
| "source": "variable1.bal", | ||
| "description": "Sample diagram node", | ||
| "codedata": { | ||
| "node": "VARIABLE", | ||
| "lineRange": { | ||
| "fileName": "main.bal", | ||
| "startLine": { | ||
| "line": 33, | ||
| "offset": 0 | ||
| }, | ||
| "endLine": { | ||
| "line": 35, | ||
| "offset": 2 | ||
| } | ||
| }, | ||
| "isNew": true, | ||
| "sourceCode": "" | ||
| }, | ||
| "typeName": "UserInfo", | ||
| "variableName": "user", | ||
| "isInput": true, | ||
| "output": { | ||
| "variable1.bal": [ | ||
| { | ||
| "range": { | ||
| "start": { | ||
| "line": 33, | ||
| "character": 67 | ||
| }, | ||
| "end": { | ||
| "line": 35, | ||
| "character": 1 | ||
| } | ||
| }, | ||
| "newText": "let UserInfo userConverted = check user.ensureType() in {\n\n}" | ||
| } | ||
| ] | ||
| } | ||
| } |
53 changes: 53 additions & 0 deletions
53
...generator-ls-extension/src/test/resources/data_mapper_convert_type/config/variable11.json
This file contains hidden or 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,53 @@ | ||
| { | ||
| "source": "variable1.bal", | ||
| "description": "Sample diagram node", | ||
| "codedata": { | ||
| "node": "VARIABLE", | ||
| "lineRange": { | ||
| "fileName": "main.bal", | ||
| "startLine": { | ||
| "line": 37, | ||
| "offset": 0 | ||
| }, | ||
| "endLine": { | ||
| "line": 39, | ||
| "offset": 2 | ||
| } | ||
| }, | ||
| "isNew": true, | ||
| "sourceCode": "" | ||
| }, | ||
| "typeName": "UserInfo", | ||
| "variableName": "user", | ||
| "isInput": true, | ||
| "output": { | ||
| "variable1.bal": [ | ||
| { | ||
| "range": { | ||
| "start": { | ||
| "line": 37, | ||
| "character": 44 | ||
| }, | ||
| "end": { | ||
| "line": 37, | ||
| "character": 44 | ||
| } | ||
| }, | ||
| "newText": " returns error?" | ||
| }, | ||
| { | ||
| "range": { | ||
| "start": { | ||
| "line": 37, | ||
| "character": 48 | ||
| }, | ||
| "end": { | ||
| "line": 39, | ||
| "character": 1 | ||
| } | ||
| }, | ||
| "newText": "let UserInfo userConverted = check user.ensureType() in {\n\n}" | ||
| } | ||
| ] | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.