From 632aa4963e5fbe5a66df61f889626953153a8739 Mon Sep 17 00:00:00 2001 From: Kalaiyarasi Date: Wed, 23 Mar 2022 10:03:57 +0530 Subject: [PATCH 01/21] [Automated] Update the native jar versions --- ballerina/Ballerina.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ballerina/Ballerina.toml b/ballerina/Ballerina.toml index 2b8a1faa..b9286f97 100644 --- a/ballerina/Ballerina.toml +++ b/ballerina/Ballerina.toml @@ -1,7 +1,7 @@ [package] org = "ballerina" name = "xmldata" -version = "2.2.1" +version = "2.2.2" authors = ["Ballerina"] keywords = ["xml", "json"] repository = "https://github.com/ballerina-platform/module-ballerina-xmldata" @@ -10,4 +10,4 @@ license = ["Apache-2.0"] distribution = "2201.0.1" [[platform.java11.dependency]] -path = "../native/build/libs/xmldata-native-2.2.1.jar" +path = "../native/build/libs/xmldata-native-2.2.2-SNAPSHOT.jar" From 4f4bf86d800a885850cc19a54ec4d75fca0a372b Mon Sep 17 00:00:00 2001 From: Kalaiyarasi Date: Wed, 23 Mar 2022 10:08:25 +0530 Subject: [PATCH 02/21] [Automated] Update the native jar versions --- ballerina/Dependencies.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index 652b144f..1174df8d 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -29,7 +29,7 @@ modules = [ [[package]] org = "ballerina" name = "xmldata" -version = "2.2.1" +version = "2.2.2" dependencies = [ {org = "ballerina", name = "jballerina.java"}, {org = "ballerina", name = "test"} From 503f24dd7b394dc224d7ff0e25467fea0ce14624 Mon Sep 17 00:00:00 2001 From: Kalaiyarasi Date: Wed, 23 Mar 2022 10:14:11 +0530 Subject: [PATCH 03/21] [Automated] Update the native jar versions --- ballerina/Dependencies.toml | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index 1174df8d..efa2fd41 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -6,6 +6,18 @@ [ballerina] dependencies-toml-version = "2" +[[package]] +org = "ballerina" +name = "io" +version = "1.2.0" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.value"} +] +modules = [ + {org = "ballerina", packageName = "io", moduleName = "io"} +] + [[package]] org = "ballerina" name = "jballerina.java" @@ -14,6 +26,14 @@ modules = [ {org = "ballerina", packageName = "jballerina.java", moduleName = "jballerina.java"} ] +[[package]] +org = "ballerina" +name = "lang.value" +version = "0.0.0" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] + [[package]] org = "ballerina" name = "test" @@ -31,6 +51,7 @@ org = "ballerina" name = "xmldata" version = "2.2.2" dependencies = [ + {org = "ballerina", name = "io"}, {org = "ballerina", name = "jballerina.java"}, {org = "ballerina", name = "test"} ] From 7e6a730c9e754076d10215d11915b8b186ac623b Mon Sep 17 00:00:00 2001 From: Kalaiyarasi Date: Wed, 23 Mar 2022 23:23:07 +0530 Subject: [PATCH 04/21] [Automated] Update the native jar versions --- ballerina/Dependencies.toml | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index efa2fd41..1174df8d 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -6,18 +6,6 @@ [ballerina] dependencies-toml-version = "2" -[[package]] -org = "ballerina" -name = "io" -version = "1.2.0" -dependencies = [ - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "lang.value"} -] -modules = [ - {org = "ballerina", packageName = "io", moduleName = "io"} -] - [[package]] org = "ballerina" name = "jballerina.java" @@ -26,14 +14,6 @@ modules = [ {org = "ballerina", packageName = "jballerina.java", moduleName = "jballerina.java"} ] -[[package]] -org = "ballerina" -name = "lang.value" -version = "0.0.0" -dependencies = [ - {org = "ballerina", name = "jballerina.java"} -] - [[package]] org = "ballerina" name = "test" @@ -51,7 +31,6 @@ org = "ballerina" name = "xmldata" version = "2.2.2" dependencies = [ - {org = "ballerina", name = "io"}, {org = "ballerina", name = "jballerina.java"}, {org = "ballerina", name = "test"} ] From bc102453f27059c8d268424e970f597ec22b734c Mon Sep 17 00:00:00 2001 From: Kalaiyarasi Date: Thu, 24 Mar 2022 10:45:23 +0530 Subject: [PATCH 05/21] [Automated] Update the native jar versions --- ballerina/Dependencies.toml | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index 1174df8d..efa2fd41 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -6,6 +6,18 @@ [ballerina] dependencies-toml-version = "2" +[[package]] +org = "ballerina" +name = "io" +version = "1.2.0" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.value"} +] +modules = [ + {org = "ballerina", packageName = "io", moduleName = "io"} +] + [[package]] org = "ballerina" name = "jballerina.java" @@ -14,6 +26,14 @@ modules = [ {org = "ballerina", packageName = "jballerina.java", moduleName = "jballerina.java"} ] +[[package]] +org = "ballerina" +name = "lang.value" +version = "0.0.0" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] + [[package]] org = "ballerina" name = "test" @@ -31,6 +51,7 @@ org = "ballerina" name = "xmldata" version = "2.2.2" dependencies = [ + {org = "ballerina", name = "io"}, {org = "ballerina", name = "jballerina.java"}, {org = "ballerina", name = "test"} ] From fc7dbd473f4cf7a26ca291324e7e61a664c566a4 Mon Sep 17 00:00:00 2001 From: Kalaiyarasi Date: Thu, 24 Mar 2022 11:41:24 +0530 Subject: [PATCH 06/21] [Automated] Update the native jar versions --- ballerina/Dependencies.toml | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index efa2fd41..1174df8d 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -6,18 +6,6 @@ [ballerina] dependencies-toml-version = "2" -[[package]] -org = "ballerina" -name = "io" -version = "1.2.0" -dependencies = [ - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "lang.value"} -] -modules = [ - {org = "ballerina", packageName = "io", moduleName = "io"} -] - [[package]] org = "ballerina" name = "jballerina.java" @@ -26,14 +14,6 @@ modules = [ {org = "ballerina", packageName = "jballerina.java", moduleName = "jballerina.java"} ] -[[package]] -org = "ballerina" -name = "lang.value" -version = "0.0.0" -dependencies = [ - {org = "ballerina", name = "jballerina.java"} -] - [[package]] org = "ballerina" name = "test" @@ -51,7 +31,6 @@ org = "ballerina" name = "xmldata" version = "2.2.2" dependencies = [ - {org = "ballerina", name = "io"}, {org = "ballerina", name = "jballerina.java"}, {org = "ballerina", name = "test"} ] From e8128cde0278b7a2b80c98072d8975a488b832f4 Mon Sep 17 00:00:00 2001 From: Kalaiyarasi Date: Thu, 24 Mar 2022 12:06:53 +0530 Subject: [PATCH 07/21] [Automated] Update the native jar versions --- ballerina/Dependencies.toml | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index 1174df8d..efa2fd41 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -6,6 +6,18 @@ [ballerina] dependencies-toml-version = "2" +[[package]] +org = "ballerina" +name = "io" +version = "1.2.0" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.value"} +] +modules = [ + {org = "ballerina", packageName = "io", moduleName = "io"} +] + [[package]] org = "ballerina" name = "jballerina.java" @@ -14,6 +26,14 @@ modules = [ {org = "ballerina", packageName = "jballerina.java", moduleName = "jballerina.java"} ] +[[package]] +org = "ballerina" +name = "lang.value" +version = "0.0.0" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] + [[package]] org = "ballerina" name = "test" @@ -31,6 +51,7 @@ org = "ballerina" name = "xmldata" version = "2.2.2" dependencies = [ + {org = "ballerina", name = "io"}, {org = "ballerina", name = "jballerina.java"}, {org = "ballerina", name = "test"} ] From 594dfe29ecbb0256b612c7d3065c9abcb5a2ed28 Mon Sep 17 00:00:00 2001 From: Kalaiyarasi Date: Fri, 25 Mar 2022 11:32:13 +0530 Subject: [PATCH 08/21] [Automated] Update the native jar versions --- ballerina/Dependencies.toml | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index efa2fd41..1174df8d 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -6,18 +6,6 @@ [ballerina] dependencies-toml-version = "2" -[[package]] -org = "ballerina" -name = "io" -version = "1.2.0" -dependencies = [ - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "lang.value"} -] -modules = [ - {org = "ballerina", packageName = "io", moduleName = "io"} -] - [[package]] org = "ballerina" name = "jballerina.java" @@ -26,14 +14,6 @@ modules = [ {org = "ballerina", packageName = "jballerina.java", moduleName = "jballerina.java"} ] -[[package]] -org = "ballerina" -name = "lang.value" -version = "0.0.0" -dependencies = [ - {org = "ballerina", name = "jballerina.java"} -] - [[package]] org = "ballerina" name = "test" @@ -51,7 +31,6 @@ org = "ballerina" name = "xmldata" version = "2.2.2" dependencies = [ - {org = "ballerina", name = "io"}, {org = "ballerina", name = "jballerina.java"}, {org = "ballerina", name = "test"} ] From 390bff6b002c67127cc6f402e30e811a84c1d23e Mon Sep 17 00:00:00 2001 From: Kalaiyarasi Date: Sun, 27 Mar 2022 22:22:50 +0530 Subject: [PATCH 09/21] [Automated] Update the native jar versions --- ballerina/Dependencies.toml | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index 1174df8d..efa2fd41 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -6,6 +6,18 @@ [ballerina] dependencies-toml-version = "2" +[[package]] +org = "ballerina" +name = "io" +version = "1.2.0" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.value"} +] +modules = [ + {org = "ballerina", packageName = "io", moduleName = "io"} +] + [[package]] org = "ballerina" name = "jballerina.java" @@ -14,6 +26,14 @@ modules = [ {org = "ballerina", packageName = "jballerina.java", moduleName = "jballerina.java"} ] +[[package]] +org = "ballerina" +name = "lang.value" +version = "0.0.0" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] + [[package]] org = "ballerina" name = "test" @@ -31,6 +51,7 @@ org = "ballerina" name = "xmldata" version = "2.2.2" dependencies = [ + {org = "ballerina", name = "io"}, {org = "ballerina", name = "jballerina.java"}, {org = "ballerina", name = "test"} ] From 166f0576a36256f64017850b96513b9d13f1827a Mon Sep 17 00:00:00 2001 From: Kalaiyarasi Date: Mon, 28 Mar 2022 00:25:05 +0530 Subject: [PATCH 10/21] [Automated] Update the native jar versions --- ballerina/Dependencies.toml | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index efa2fd41..1174df8d 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -6,18 +6,6 @@ [ballerina] dependencies-toml-version = "2" -[[package]] -org = "ballerina" -name = "io" -version = "1.2.0" -dependencies = [ - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "lang.value"} -] -modules = [ - {org = "ballerina", packageName = "io", moduleName = "io"} -] - [[package]] org = "ballerina" name = "jballerina.java" @@ -26,14 +14,6 @@ modules = [ {org = "ballerina", packageName = "jballerina.java", moduleName = "jballerina.java"} ] -[[package]] -org = "ballerina" -name = "lang.value" -version = "0.0.0" -dependencies = [ - {org = "ballerina", name = "jballerina.java"} -] - [[package]] org = "ballerina" name = "test" @@ -51,7 +31,6 @@ org = "ballerina" name = "xmldata" version = "2.2.2" dependencies = [ - {org = "ballerina", name = "io"}, {org = "ballerina", name = "jballerina.java"}, {org = "ballerina", name = "test"} ] From ebc382b9c09c6dcd79752c4ee3c8b067292f2df9 Mon Sep 17 00:00:00 2001 From: Kalaiyarasi Date: Mon, 28 Mar 2022 00:26:14 +0530 Subject: [PATCH 11/21] [Automated] Update the native jar versions --- ballerina/Dependencies.toml | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index 1174df8d..efa2fd41 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -6,6 +6,18 @@ [ballerina] dependencies-toml-version = "2" +[[package]] +org = "ballerina" +name = "io" +version = "1.2.0" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.value"} +] +modules = [ + {org = "ballerina", packageName = "io", moduleName = "io"} +] + [[package]] org = "ballerina" name = "jballerina.java" @@ -14,6 +26,14 @@ modules = [ {org = "ballerina", packageName = "jballerina.java", moduleName = "jballerina.java"} ] +[[package]] +org = "ballerina" +name = "lang.value" +version = "0.0.0" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] + [[package]] org = "ballerina" name = "test" @@ -31,6 +51,7 @@ org = "ballerina" name = "xmldata" version = "2.2.2" dependencies = [ + {org = "ballerina", name = "io"}, {org = "ballerina", name = "jballerina.java"}, {org = "ballerina", name = "test"} ] From c0cdd19f3871f1eede066728f6d43241a254e120 Mon Sep 17 00:00:00 2001 From: Kalaiyarasi Date: Wed, 30 Mar 2022 13:20:26 +0530 Subject: [PATCH 12/21] [Automated] Update the native jar versions --- ballerina/Dependencies.toml | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index efa2fd41..1174df8d 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -6,18 +6,6 @@ [ballerina] dependencies-toml-version = "2" -[[package]] -org = "ballerina" -name = "io" -version = "1.2.0" -dependencies = [ - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "lang.value"} -] -modules = [ - {org = "ballerina", packageName = "io", moduleName = "io"} -] - [[package]] org = "ballerina" name = "jballerina.java" @@ -26,14 +14,6 @@ modules = [ {org = "ballerina", packageName = "jballerina.java", moduleName = "jballerina.java"} ] -[[package]] -org = "ballerina" -name = "lang.value" -version = "0.0.0" -dependencies = [ - {org = "ballerina", name = "jballerina.java"} -] - [[package]] org = "ballerina" name = "test" @@ -51,7 +31,6 @@ org = "ballerina" name = "xmldata" version = "2.2.2" dependencies = [ - {org = "ballerina", name = "io"}, {org = "ballerina", name = "jballerina.java"}, {org = "ballerina", name = "test"} ] From 0d1b7d9d16e599a3f7c1ca403f4651b6f5fdcc29 Mon Sep 17 00:00:00 2001 From: Kalaiyarasi Date: Wed, 30 Mar 2022 13:57:24 +0530 Subject: [PATCH 13/21] Update output of toRecord() impl --- ballerina/tests/xml_to_record_test.bal | 25 ++++---- docs/spec/spec.md | 15 +---- .../ballerina/stdlib/xmldata/XmlToJson.java | 57 ++++++++----------- 3 files changed, 39 insertions(+), 58 deletions(-) diff --git a/ballerina/tests/xml_to_record_test.bal b/ballerina/tests/xml_to_record_test.bal index 65b5c10e..b0bb8e22 100644 --- a/ballerina/tests/xml_to_record_test.bal +++ b/ballerina/tests/xml_to_record_test.bal @@ -60,9 +60,9 @@ type Invoice record { PurchesedItems PurchesedItems; Address1 Address; string _xmlns?; - string _xmlns_ns?; + string _xmlns\:ns?; string _attr?; - string _ns_attr?; + string _ns\:attr?; }; type PurchesedItems record { @@ -76,6 +76,7 @@ type Purchase record { type ItemCode record { string _discount; + string \#content; }; type Address1 record { @@ -111,7 +112,7 @@ function testToRecordComplexXmlElement() returns error? { {ItemCode: "223345", Count: 10}, {ItemCode: "223300", Count: 7}, { - ItemCode: {"_discount": "22%", "#content": "200777"}, + ItemCode: {_discount: "22%", \#content: "200777"}, Count: 7 } ] @@ -124,9 +125,9 @@ function testToRecordComplexXmlElement() returns error? { _xmlns: "" }, _xmlns: "example.com", - _xmlns_ns: "ns.com", + _xmlns\:ns: "ns.com", _attr: "attr-val", - _ns_attr: "ns-attr-val" + _ns\:attr: "ns-attr-val" } }; Order actual = check toRecord(e2); @@ -144,7 +145,7 @@ function testToRecordComplexXmlElementWithoutPreserveNamespaces() returns error? {ItemCode: "223345", Count: 10}, {ItemCode: "223300", Count: 7}, { - ItemCode: {"_discount": "22%", "#content": "200777"}, + ItemCode: {_discount: "22%", \#content: "200777"}, Count: 7 } ] @@ -264,8 +265,8 @@ type r2 record { }; type Root2 record { - string _xmlns_ns; - string _ns_x; + string _xmlns\:ns; + string _ns\:x; string _x; }; @@ -277,8 +278,8 @@ isolated function testToRecordWithMultipleAttributesAndNamespaces() returns Erro r2 expected = { Root: { - _xmlns_ns: "ns.com", - _ns_x: "y", + _xmlns\:ns: "ns.com", + _ns\:x: "y", _x: "z" } }; @@ -476,7 +477,7 @@ type BookStore2 record { Address3 address; Codes codes; string _status; - string _xmlns_ns0; + string _xmlns\:ns0; }; @test:Config { @@ -515,7 +516,7 @@ isolated function testToRecordWithNamespaces() returns error? { codes: { item: [4, 8, 9] }, - _xmlns_ns0: "http://sample.com/test", + _xmlns\:ns0: "http://sample.com/test", _status: "online" } }; diff --git a/docs/spec/spec.md b/docs/spec/spec.md index 9b5d345a..8dd324db 100644 --- a/docs/spec/spec.md +++ b/docs/spec/spec.md @@ -24,7 +24,7 @@ The conforming implementation of the specification is released and included in t * 2.1 [Record](#23-record) 3. [Rules](#3-rules) * 3.1 [Rules for XML to JSON Conversion](#31-rules-for-xml-to-json-conversion) - * 3.2 [Rules for XML to Record Conversion](#32-rules-for-xml-to-json-conversion) + * 3.2 [Rules for XML to Record Conversion](#32-rules-for-xml-to-record-conversion) * 3.1 [Rules for JSON to XML Conversion](#33-rules-for-json-to-xml-conversion) 4. [Operations](#4-operations) * 4.1 [XML to JSON Conversion](#41-xml-to-json-conversion) @@ -235,19 +235,6 @@ The following API returns the record to the given XML structure by configuring t public isolated function toRecord(xml xmlValue, boolean preserveNamespaces = true, typedesc returnType = <>) returns returnType|Error ``` -The XML value may not have a key to convert JSON data. Hence, Ballerina uses a default key as a `#content` to handle this case. - -Let's consider this, -```ballerina -xml x3 = xml `Book`; -record{} result = check xmldata:toRecord(x3); -``` -Output of this is, -```ballerina -{"ns0:bookStore":{"_xmlns_ns0":"http://sample.com/test","_status":"online","#content":"Book"}} -``` -Here, `Book` does not have a key. So, JSON data introduces a key as `#content`. but it is not mapped to any field in the Ballerina record. If the user needs to convert these XML values to a Ballerina record, it should be an open record with other fields. - #### 4.2.1 Sample ```ballerina diff --git a/native/src/main/java/io/ballerina/stdlib/xmldata/XmlToJson.java b/native/src/main/java/io/ballerina/stdlib/xmldata/XmlToJson.java index 977646a1..881258cd 100644 --- a/native/src/main/java/io/ballerina/stdlib/xmldata/XmlToJson.java +++ b/native/src/main/java/io/ballerina/stdlib/xmldata/XmlToJson.java @@ -79,7 +79,7 @@ public static Object toJson(BXml xml, BMap options) { .getValue(); boolean preserveNamespaces = ((Boolean) options.get(StringUtils.fromString(Constants.OPTIONS_PRESERVE_NS))); return convertToJSON(xml, attributePrefix, preserveNamespaces, new AttributeManager(), - null, "", COLON); + null, ""); } catch (Exception e) { return XmlDataUtils.getError(e.getMessage()); } @@ -87,8 +87,7 @@ public static Object toJson(BXml xml, BMap options) { public static Object toJson(BXml xml, boolean preserveNamespaces, Type type) { try { - return convertToJSON(xml, UNDERSCORE, preserveNamespaces, new AttributeManager(), - type, "", UNDERSCORE); + return convertToJSON(xml, UNDERSCORE, preserveNamespaces, new AttributeManager(), type, ""); } catch (Exception e) { return XmlDataUtils.getError(e.getMessage()); } @@ -103,18 +102,17 @@ public static Object toJson(BXml xml, boolean preserveNamespaces, Type type) { * @return JSON representation of the given xml object */ public static Object convertToJSON(BXml xml, String attributePrefix, boolean preserveNamespaces, - AttributeManager attributeManager, Type type, String uniqueKey, - String namespaceDelimiter) { + AttributeManager attributeManager, Type type, String uniqueKey) { if (xml instanceof BXmlItem) { return convertElement((BXmlItem) xml, attributePrefix, preserveNamespaces, attributeManager, type, - uniqueKey, namespaceDelimiter); + uniqueKey); } else if (xml instanceof BXmlSequence) { BXmlSequence xmlSequence = (BXmlSequence) xml; if (xmlSequence.isEmpty()) { return StringUtils.fromString(EMPTY_STRING); } Object seq = convertBXmlSequence(xmlSequence, attributePrefix, preserveNamespaces, attributeManager, type, - uniqueKey, namespaceDelimiter); + uniqueKey); if (seq == null) { return newJsonList(); } @@ -137,14 +135,14 @@ public static Object convertToJSON(BXml xml, String attributePrefix, boolean pre */ private static Object convertElement(BXmlItem xmlItem, String attributePrefix, boolean preserveNamespaces, AttributeManager attributeManager, Type type, - String uniqueKey, String namespaceDelimiter) { + String uniqueKey) { BMap childrenData = newJsonMap(); processAttributes(xmlItem, attributePrefix, childrenData, attributeManager, type, uniqueKey, - namespaceDelimiter, preserveNamespaces); + preserveNamespaces); String uKeyValue = getUniqueKey(xmlItem, preserveNamespaces, uniqueKey); String keyValue = getElementKey(xmlItem, preserveNamespaces); Object children = convertBXmlSequence(xmlItem.getChildrenSeq(), attributePrefix, - preserveNamespaces, attributeManager, type, uKeyValue, namespaceDelimiter); + preserveNamespaces, attributeManager, type, uKeyValue); BMap rootNode = newJsonMap(); if (childrenData.size() > 0) { if (children instanceof BMap) { @@ -174,14 +172,13 @@ private static Object convertElement(BXmlItem xmlItem, String attributePrefix, private static void processAttributes(BXmlItem xmlItem, String attributePrefix, BMap mapData, AttributeManager attributeManager, Type type, - String uniqueKey, String namespaceDelimiter, boolean preserveNamespaces) { + String uniqueKey, boolean preserveNamespaces) { LinkedHashMap tempAttributeMap = new LinkedHashMap<>(); if (attributeManager.getMap().isEmpty()) { - tempAttributeMap = collectAttributesAndNamespaces(xmlItem, namespaceDelimiter, preserveNamespaces); + tempAttributeMap = collectAttributesAndNamespaces(xmlItem, preserveNamespaces); attributeManager.initializeMap(tempAttributeMap); } else { - LinkedHashMap newAttributeMap = collectAttributesAndNamespaces(xmlItem, namespaceDelimiter, - preserveNamespaces); + LinkedHashMap newAttributeMap = collectAttributesAndNamespaces(xmlItem, preserveNamespaces); LinkedHashMap attributeMap = attributeManager.getMap(); for (Map.Entry entrySet : newAttributeMap.entrySet()) { String key = entrySet.getKey(); @@ -259,7 +256,7 @@ private static void putAsBStrings(BMap map, String key, Object */ private static Object convertBXmlSequence(BXmlSequence xmlSequence, String attributePrefix, boolean preserveNamespaces, AttributeManager attributeManager, - Type type, String uniqueKey, String namespaceDelimiter) { + Type type, String uniqueKey) { List sequence = xmlSequence.getChildrenList(); List newSequence = new ArrayList<>(); for (BXml value: sequence) { @@ -272,15 +269,15 @@ private static Object convertBXmlSequence(BXmlSequence xmlSequence, String attri return null; } return convertHeterogeneousSequence(attributePrefix, preserveNamespaces, newSequence, attributeManager, type, - uniqueKey, namespaceDelimiter); + uniqueKey); } private static Object convertHeterogeneousSequence(String attributePrefix, boolean preserveNamespaces, List sequence, AttributeManager attributeManager, - Type type, String uniqueKey, String namespaceDelimiter) { + Type type, String uniqueKey) { if (sequence.size() == 1) { return convertToJSON(sequence.get(0), attributePrefix, preserveNamespaces, attributeManager, type, - uniqueKey, namespaceDelimiter); + uniqueKey); } BMap mapJson = newJsonMap(); for (BXml bxml : sequence) { @@ -304,7 +301,7 @@ private static Object convertHeterogeneousSequence(String attributePrefix, boole } else { BString elementName = fromString(getElementKey((BXmlItem) bxml, preserveNamespaces)); Object result = convertToJSON(bxml, attributePrefix, preserveNamespaces, attributeManager, - type, uniqueKey, namespaceDelimiter); + type, uniqueKey); result = validateResult(result, elementName); Object value = mapJson.get(elementName); if (value == null) { @@ -353,7 +350,6 @@ private static BMap newJsonMap() { * @param element XML element to extract attributes and namespaces */ private static LinkedHashMap collectAttributesAndNamespaces(BXmlItem element, - String namespaceDelimiter, boolean preserveNamespaces) { LinkedHashMap attributeMap = new LinkedHashMap<>(); BMap attributesMap = element.getAttributesMap(); @@ -363,14 +359,14 @@ private static LinkedHashMap collectAttributesAndNamespaces(BXml if (preserveNamespaces) { if (isNamespacePrefixEntry(entry)) { addNamespacePrefixAttribute(attributeMap, entry.getKey().getValue(), - entry.getValue().getValue(), namespaceDelimiter); + entry.getValue().getValue()); } else { addAttributePreservingNamespace(attributeMap, nsPrefixMap, entry.getKey().getValue(), - entry.getValue().getValue(), namespaceDelimiter); + entry.getValue().getValue()); } } else { preserveNonNamespacesAttributes(attributeMap, nsPrefixMap, entry.getKey().getValue(), - entry.getValue().getValue(), namespaceDelimiter); + entry.getValue().getValue()); } } return attributeMap; @@ -378,30 +374,27 @@ private static LinkedHashMap collectAttributesAndNamespaces(BXml private static void preserveNonNamespacesAttributes(LinkedHashMap attributeMap, Map nsPrefixMap, - String attributeKey, String attributeValue, - String namespaceDelimiter) { + String attributeKey, String attributeValue) { // The namespace-related key will contain the pattern as `{link}suffix` if (!Pattern.matches("\\{.*\\}.*", attributeKey)) { addAttributePreservingNamespace(attributeMap, nsPrefixMap, attributeKey, - attributeValue, namespaceDelimiter); + attributeValue); } } private static void addNamespacePrefixAttribute(LinkedHashMap attributeMap, - String attributeKey, String attributeValue, - String namespaceDelimiter) { + String attributeKey, String attributeValue) { String prefix = attributeKey.substring(NS_PREFIX_BEGIN_INDEX); if (prefix.equals(XMLNS)) { attributeMap.put(prefix, attributeValue); } else { - attributeMap.put(XMLNS + namespaceDelimiter + prefix, attributeValue); + attributeMap.put(XMLNS + COLON + prefix, attributeValue); } } private static void addAttributePreservingNamespace(LinkedHashMap attributeMap, Map nsPrefixMap, - String attributeKey, String attributeValue, - String namespaceDelimiter) { + String attributeKey, String attributeValue) { int nsEndIndex = attributeKey.lastIndexOf('}'); if (nsEndIndex > 0) { String ns = attributeKey.substring(1, nsEndIndex); @@ -413,7 +406,7 @@ private static void addAttributePreservingNamespace(LinkedHashMap Date: Wed, 30 Mar 2022 14:41:35 +0530 Subject: [PATCH 14/21] [Automated] Update the native jar versions --- ballerina/Dependencies.toml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index 1174df8d..a85dc3d0 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -6,6 +6,19 @@ [ballerina] dependencies-toml-version = "2" +[[package]] +org = "ballerina" +name = "io" +version = "1.2.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.value"} +] +modules = [ + {org = "ballerina", packageName = "io", moduleName = "io"} +] + [[package]] org = "ballerina" name = "jballerina.java" @@ -14,6 +27,15 @@ modules = [ {org = "ballerina", packageName = "jballerina.java", moduleName = "jballerina.java"} ] +[[package]] +org = "ballerina" +name = "lang.value" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] + [[package]] org = "ballerina" name = "test" @@ -31,6 +53,7 @@ org = "ballerina" name = "xmldata" version = "2.2.2" dependencies = [ + {org = "ballerina", name = "io"}, {org = "ballerina", name = "jballerina.java"}, {org = "ballerina", name = "test"} ] From b272805de0ad88385dc543c706939e11b7dea0c5 Mon Sep 17 00:00:00 2001 From: Kalaiyarasi Date: Wed, 30 Mar 2022 14:46:15 +0530 Subject: [PATCH 15/21] [Automated] Update the native jar versions --- ballerina/Dependencies.toml | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index a85dc3d0..1174df8d 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -6,19 +6,6 @@ [ballerina] dependencies-toml-version = "2" -[[package]] -org = "ballerina" -name = "io" -version = "1.2.0" -scope = "testOnly" -dependencies = [ - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "lang.value"} -] -modules = [ - {org = "ballerina", packageName = "io", moduleName = "io"} -] - [[package]] org = "ballerina" name = "jballerina.java" @@ -27,15 +14,6 @@ modules = [ {org = "ballerina", packageName = "jballerina.java", moduleName = "jballerina.java"} ] -[[package]] -org = "ballerina" -name = "lang.value" -version = "0.0.0" -scope = "testOnly" -dependencies = [ - {org = "ballerina", name = "jballerina.java"} -] - [[package]] org = "ballerina" name = "test" @@ -53,7 +31,6 @@ org = "ballerina" name = "xmldata" version = "2.2.2" dependencies = [ - {org = "ballerina", name = "io"}, {org = "ballerina", name = "jballerina.java"}, {org = "ballerina", name = "test"} ] From 669a811b9ddce5fd4b1591618b983ad63b00999d Mon Sep 17 00:00:00 2001 From: Kalaiyarasi Date: Wed, 30 Mar 2022 15:02:06 +0530 Subject: [PATCH 16/21] [Automated] Update the native jar versions --- ballerina/Dependencies.toml | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index 1174df8d..efa2fd41 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -6,6 +6,18 @@ [ballerina] dependencies-toml-version = "2" +[[package]] +org = "ballerina" +name = "io" +version = "1.2.0" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.value"} +] +modules = [ + {org = "ballerina", packageName = "io", moduleName = "io"} +] + [[package]] org = "ballerina" name = "jballerina.java" @@ -14,6 +26,14 @@ modules = [ {org = "ballerina", packageName = "jballerina.java", moduleName = "jballerina.java"} ] +[[package]] +org = "ballerina" +name = "lang.value" +version = "0.0.0" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] + [[package]] org = "ballerina" name = "test" @@ -31,6 +51,7 @@ org = "ballerina" name = "xmldata" version = "2.2.2" dependencies = [ + {org = "ballerina", name = "io"}, {org = "ballerina", name = "jballerina.java"}, {org = "ballerina", name = "test"} ] From a8389717dddbd072bd3d8b84758c8befe7eb9137 Mon Sep 17 00:00:00 2001 From: Kalaiyarasi Date: Wed, 30 Mar 2022 18:33:11 +0530 Subject: [PATCH 17/21] [Automated] Update the native jar versions --- ballerina/Dependencies.toml | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index efa2fd41..1174df8d 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -6,18 +6,6 @@ [ballerina] dependencies-toml-version = "2" -[[package]] -org = "ballerina" -name = "io" -version = "1.2.0" -dependencies = [ - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "lang.value"} -] -modules = [ - {org = "ballerina", packageName = "io", moduleName = "io"} -] - [[package]] org = "ballerina" name = "jballerina.java" @@ -26,14 +14,6 @@ modules = [ {org = "ballerina", packageName = "jballerina.java", moduleName = "jballerina.java"} ] -[[package]] -org = "ballerina" -name = "lang.value" -version = "0.0.0" -dependencies = [ - {org = "ballerina", name = "jballerina.java"} -] - [[package]] org = "ballerina" name = "test" @@ -51,7 +31,6 @@ org = "ballerina" name = "xmldata" version = "2.2.2" dependencies = [ - {org = "ballerina", name = "io"}, {org = "ballerina", name = "jballerina.java"}, {org = "ballerina", name = "test"} ] From 124f1222a9a3a508867b87903952f9c848fc142c Mon Sep 17 00:00:00 2001 From: Kalaiyarasi Date: Wed, 30 Mar 2022 19:12:21 +0530 Subject: [PATCH 18/21] Remove arrayEntryTag and attributePrefix initialization --- ballerina/tests/xml_from_json_test.bal | 84 +++++++++++++++++++ ballerina/tests/xml_to_record_test.bal | 35 -------- ballerina/xmldata.bal | 68 ++++++++------- .../ballerina/stdlib/xmldata/XmlToJson.java | 6 +- 4 files changed, 127 insertions(+), 66 deletions(-) diff --git a/ballerina/tests/xml_from_json_test.bal b/ballerina/tests/xml_from_json_test.bal index be67c3d2..9b053ee1 100644 --- a/ballerina/tests/xml_from_json_test.bal +++ b/ballerina/tests/xml_from_json_test.bal @@ -769,3 +769,87 @@ isolated function testWithAttribute3() { test:assertFail("failed to convert json to xml"); } } + +type Order record { + Invoice Invoice; +}; + +type Invoice record { + PurchesedItems PurchesedItems; + Address1 Address; + string _xmlns?; + string _xmlns\:ns?; + string _attr?; + string _ns\:attr?; +}; + +type PurchesedItems record { + Purchase[] PLine; +}; + +type Purchase record { + string|ItemCode ItemCode; + int Count; +}; + +type ItemCode record { + string _discount; + string \#content; +}; + +type Address1 record { + string StreetAddress; + string City; + int Zip; + string Country; + string _xmlns?; +}; + +@test:Config { + groups: ["fromJson"] +} +isolated function testfromjsonwithRecord() { + Order data = { + Invoice: { + PurchesedItems: { + PLine: [ + {ItemCode: "223345", Count: 10}, + {ItemCode: "223300", Count: 7}, + { + ItemCode: {_discount: "22%", \#content: "200777"}, + Count: 7 + } + ] + }, + Address: { + StreetAddress: "20, Palm grove, Colombo 3", + City: "Colombo", + Zip: 300, + Country: "LK" + }, + "_attr": "attr-val", + "_xmlns": "example.com", + "_xmlns:ns": "ns.com" + } + }; + string expected = "" + + "" + + "22334510" + + "2233007" + + "2007777" + + "" + + "
" + + "20, Palm grove, Colombo 3" + + "Colombo" + + "300" + + "LK" + + "
" + + "
"; + json jsonData = data.toJson(); + xml?|error result = fromJson(jsonData, {attributePrefix: "_"}); + if result is xml { + test:assertEquals(result.toString(), expected.toString()); + } else { + test:assertFail("failed to convert json to xml"); + } +} diff --git a/ballerina/tests/xml_to_record_test.bal b/ballerina/tests/xml_to_record_test.bal index b0bb8e22..61bfc1c8 100644 --- a/ballerina/tests/xml_to_record_test.bal +++ b/ballerina/tests/xml_to_record_test.bal @@ -52,41 +52,6 @@ isolated function testToRecordWithEscapedString() returns error? { test:assertEquals(actual, expected, msg = "testToRecordWithEscapedString result incorrect"); } -type Order record { - Invoice Invoice; -}; - -type Invoice record { - PurchesedItems PurchesedItems; - Address1 Address; - string _xmlns?; - string _xmlns\:ns?; - string _attr?; - string _ns\:attr?; -}; - -type PurchesedItems record { - Purchase[] PLine; -}; - -type Purchase record { - string|ItemCode ItemCode; - int Count; -}; - -type ItemCode record { - string _discount; - string \#content; -}; - -type Address1 record { - string StreetAddress; - string City; - int Zip; - string Country; - string _xmlns?; -}; - xml e2 = xml ` 22334510 diff --git a/ballerina/xmldata.bal b/ballerina/xmldata.bal index 8d16d71d..d51c5e7e 100644 --- a/ballerina/xmldata.bal +++ b/ballerina/xmldata.bal @@ -43,9 +43,13 @@ public type JsonOptions record { # + return - XML representation of the given JSON if the JSON is # successfully converted or else an `xmldata:Error` public isolated function fromJson(json jsonValue, JsonOptions options = {}) returns xml?|Error { + JsonOptions newOptions = { + arrayEntryTag: options.arrayEntryTag == "" ? "item" : options.arrayEntryTag, + attributePrefix: options.attributePrefix == "" ? "@" : options.attributePrefix + }; if !isSingleNode(jsonValue) { - return getElement("root", check traverseNode(jsonValue, {}, options), - check getAttributesMap(jsonValue, options = options)); + return getElement("root", check traverseNode(jsonValue, {}, newOptions), newOptions, + check getAttributesMap(jsonValue, newOptions)); } else { map|error jMap = jsonValue.ensureType(); if jMap is map { @@ -54,15 +58,15 @@ public isolated function fromJson(json jsonValue, JsonOptions options = {}) retu } json value = jMap.toArray()[0]; if value is json[] { - return getElement("root", check traverseNode(value, {}, options, jMap.keys()[0]), - check getAttributesMap(value, options = options)); + return getElement("root", check traverseNode(value, {}, newOptions, jMap.keys()[0]), newOptions, + check getAttributesMap(value, newOptions)); } else { string key = jMap.keys()[0]; if key == CONTENT { return xml:createText(value.toString()); } - return getElement(jMap.keys()[0], check traverseNode(value, {}, options), - check getAttributesMap(value, options = options)); + return getElement(jMap.keys()[0], check traverseNode(value, {}, newOptions), newOptions, + check getAttributesMap(value, newOptions)); } } if jsonValue !is null { @@ -73,23 +77,22 @@ public isolated function fromJson(json jsonValue, JsonOptions options = {}) retu } } -isolated function traverseNode(json jNode, map parentNamespaces, JsonOptions options = {}, +isolated function traverseNode(json jNode, map parentNamespaces, JsonOptions options, string? key = ()) returns xml|Error { - string arrayEntryTag = options.arrayEntryTag == "" ? "item" : options.arrayEntryTag; - string attributePrefix = options.attributePrefix == "" ? "@" : options.attributePrefix; xml xNode = xml ``; if jNode is map { foreach [string, json] [k, v] in jNode.entries() { - if !k.startsWith(attributePrefix) { + if !k.startsWith(options.attributePrefix) { if k == CONTENT { xNode += xml:createText(v.toString()); } else if v is json[] { - xml node = check traverseNode(v, check getNamespacesMap(v, parentNamespaces, options), options, k); + xml node = check traverseNode(v, check getNamespacesMap(v, options, parentNamespaces), options, k); xNode += node; } else { xml node = check getElement(k, check traverseNode(v, - check getNamespacesMap(v, parentNamespaces, options), options), - check getAttributesMap(v, parentNamespaces, options = options)); + check getNamespacesMap(v, options, parentNamespaces), options), + options, + check getAttributesMap(v, options, parentNamespaces)); xNode += node; } } @@ -100,11 +103,12 @@ isolated function traverseNode(json jNode, map parentNamespaces, JsonOpt if (key is string) { arrayEntryTagKey = key; } else { - arrayEntryTagKey = arrayEntryTag; + arrayEntryTagKey = options.arrayEntryTag; } xml item = check getElement(arrayEntryTagKey, check traverseNode(i, - check getNamespacesMap(i, parentNamespaces, options)), - check getAttributesMap(i, parentNamespaces, options = options)); + check getNamespacesMap(i, options, parentNamespaces), options), + options, + check getAttributesMap(i, options, parentNamespaces)); xNode += item; } } else { @@ -124,9 +128,9 @@ isolated function isSingleNode(json node) returns boolean { return true; } -isolated function getElement(string name, xml children, map attributes = {}, JsonOptions options = {}) +isolated function getElement(string name, xml children, JsonOptions options, map attributes = {}) returns xml|Error { - string attributePrefix = options.attributePrefix == "" ? "@" : options.attributePrefix; + string attributePrefix = options.attributePrefix; xml:Element element; int? index = name.indexOf(":"); if index is int { @@ -149,9 +153,9 @@ isolated function getElement(string name, xml children, map attributes = return element; } -isolated function getAttributesMap(json jTree, map parentNamespaces = {}, JsonOptions options = {}) +isolated function getAttributesMap(json jTree, JsonOptions options, map parentNamespaces = {}) returns map|Error { - string attributePrefix = options.attributePrefix == "" ? "@" : options.attributePrefix; + string attributePrefix = options.attributePrefix; map attributes = parentNamespaces.clone(); map|error attr = jTree.ensureType(); if attr is map { @@ -160,9 +164,12 @@ isolated function getAttributesMap(json jTree, map parentNamespaces = {} if v is map || v is json[] { return error Error("attribute cannot be an object or array"); } - if k.startsWith(attributePrefix + "xmlns") { - string prefix = k.substring(k.indexOf(":") + 1); - attributes[string `{${XMLNS_NAMESPACE_URI}}${prefix}`] = v.toString(); + int? index = k.indexOf(":"); + if index is int { + if k.startsWith(attributePrefix + "xmlns") { + string prefix = k.substring(index + 1); + attributes[string `{${XMLNS_NAMESPACE_URI}}${prefix}`] = v.toString(); + } } else { attributes[k.substring(1)] = v.toString(); } @@ -172,20 +179,25 @@ isolated function getAttributesMap(json jTree, map parentNamespaces = {} return attributes; } -isolated function getNamespacesMap(json jTree, map parentNamespaces = {}, JsonOptions options = {}) +isolated function getNamespacesMap(json jTree, JsonOptions options, map parentNamespaces = {}) returns map|Error { - string attributePrefix = options.attributePrefix == "" ? "@" : options.attributePrefix; + string attributePrefix = options.attributePrefix; map namespaces = parentNamespaces.clone(); map|error attr = jTree.ensureType(); if attr is map { foreach [string, json] [k, v] in attr.entries() { if k.startsWith(attributePrefix) { if v is map || v is json[] { - return error Error("attribute cannot be an object or array"); + return error Error("attribute cannot be an object or array."); } if k.startsWith(attributePrefix + "xmlns") { - string prefix = k.substring(k.indexOf(":") + 1); - namespaces[string `{${XMLNS_NAMESPACE_URI}}${prefix}`] = v.toString(); + int? index = k.indexOf(":"); + if index is int { + string prefix = k.substring(index + 1); + namespaces[string `{${XMLNS_NAMESPACE_URI}}${prefix}`] = v.toString(); + } else { + namespaces[string `{${XMLNS_NAMESPACE_URI}}`] = v.toString(); + } } } } diff --git a/native/src/main/java/io/ballerina/stdlib/xmldata/XmlToJson.java b/native/src/main/java/io/ballerina/stdlib/xmldata/XmlToJson.java index 881258cd..dfb3482f 100644 --- a/native/src/main/java/io/ballerina/stdlib/xmldata/XmlToJson.java +++ b/native/src/main/java/io/ballerina/stdlib/xmldata/XmlToJson.java @@ -170,9 +170,9 @@ private static Object convertElement(BXmlItem xmlItem, String attributePrefix, return rootNode; } - private static void processAttributes(BXmlItem xmlItem, String attributePrefix, - BMap mapData, AttributeManager attributeManager, Type type, - String uniqueKey, boolean preserveNamespaces) { + private static void processAttributes(BXmlItem xmlItem, String attributePrefix, BMap mapData, + AttributeManager attributeManager, Type type, String uniqueKey, + boolean preserveNamespaces) { LinkedHashMap tempAttributeMap = new LinkedHashMap<>(); if (attributeManager.getMap().isEmpty()) { tempAttributeMap = collectAttributesAndNamespaces(xmlItem, preserveNamespaces); From cb281ebfcea087be674be50e0d53964e5d46bca6 Mon Sep 17 00:00:00 2001 From: Kalaiyarasi Date: Thu, 31 Mar 2022 09:31:38 +0530 Subject: [PATCH 19/21] Remove double quotes --- ballerina/tests/xml_from_json_test.bal | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ballerina/tests/xml_from_json_test.bal b/ballerina/tests/xml_from_json_test.bal index 9b053ee1..b6c28644 100644 --- a/ballerina/tests/xml_from_json_test.bal +++ b/ballerina/tests/xml_from_json_test.bal @@ -827,9 +827,9 @@ isolated function testfromjsonwithRecord() { Zip: 300, Country: "LK" }, - "_attr": "attr-val", - "_xmlns": "example.com", - "_xmlns:ns": "ns.com" + _attr: "attr-val", + _xmlns: "example.com", + _xmlns\:ns: "ns.com" } }; string expected = "" + From f60ad196784dac8177287c2400725ec850b02bbf Mon Sep 17 00:00:00 2001 From: Kalaiyarasi Date: Tue, 12 Apr 2022 16:16:09 +0530 Subject: [PATCH 20/21] Remove new JSON option initialization --- ballerina/xmldata.bal | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/ballerina/xmldata.bal b/ballerina/xmldata.bal index d51c5e7e..b9ea0d7c 100644 --- a/ballerina/xmldata.bal +++ b/ballerina/xmldata.bal @@ -43,13 +43,9 @@ public type JsonOptions record { # + return - XML representation of the given JSON if the JSON is # successfully converted or else an `xmldata:Error` public isolated function fromJson(json jsonValue, JsonOptions options = {}) returns xml?|Error { - JsonOptions newOptions = { - arrayEntryTag: options.arrayEntryTag == "" ? "item" : options.arrayEntryTag, - attributePrefix: options.attributePrefix == "" ? "@" : options.attributePrefix - }; if !isSingleNode(jsonValue) { - return getElement("root", check traverseNode(jsonValue, {}, newOptions), newOptions, - check getAttributesMap(jsonValue, newOptions)); + return getElement("root", check traverseNode(jsonValue, {}, options), options, + check getAttributesMap(jsonValue, options)); } else { map|error jMap = jsonValue.ensureType(); if jMap is map { @@ -58,15 +54,15 @@ public isolated function fromJson(json jsonValue, JsonOptions options = {}) retu } json value = jMap.toArray()[0]; if value is json[] { - return getElement("root", check traverseNode(value, {}, newOptions, jMap.keys()[0]), newOptions, - check getAttributesMap(value, newOptions)); + return getElement("root", check traverseNode(value, {}, options, jMap.keys()[0]), options, + check getAttributesMap(value, options)); } else { string key = jMap.keys()[0]; if key == CONTENT { return xml:createText(value.toString()); } - return getElement(jMap.keys()[0], check traverseNode(value, {}, newOptions), newOptions, - check getAttributesMap(value, newOptions)); + return getElement(jMap.keys()[0], check traverseNode(value, {}, options), options, + check getAttributesMap(value, options)); } } if jsonValue !is null { From 1f2c6c32285f9e01f466651a350d2eb276ad8301 Mon Sep 17 00:00:00 2001 From: Kalaiyarasi Date: Mon, 18 Apr 2022 08:39:43 +0530 Subject: [PATCH 21/21] Update the change log file --- changelog.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index f2de7041..1b224751 100644 --- a/changelog.md +++ b/changelog.md @@ -7,7 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Added -- [[2406] Add `toRecord` function which converts an XML to a Record](https://github.com/ballerina-platform/ballerina-standard-library/issues/2406) + +### Fixed +- [Fix the limitations of using the colon in the output of the `toRecord`](https://github.com/ballerina-platform/module-ballerina-xmldata/pull/418) + +## [2.1.0] - 2021-12-13 + +### Added +- [Add `toRecord` function which converts an XML to a Record](https://github.com/ballerina-platform/ballerina-standard-library/issues/2406) ## [1.1.0-alpha6] - 2021-04-02