From b9494e1f3a249d099e76b67e0927e7e93a662d54 Mon Sep 17 00:00:00 2001 From: prakanth <50439067+prakanth97@users.noreply.github.com> Date: Mon, 30 Oct 2023 13:28:29 +0530 Subject: [PATCH] Handle reference type properly --- ballerina/tests/fromXml_test.bal | 2 +- .../io/ballerina/stdlib/data/xml/XmlParser.java | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/ballerina/tests/fromXml_test.bal b/ballerina/tests/fromXml_test.bal index 72db611..d48a99c 100644 --- a/ballerina/tests/fromXml_test.bal +++ b/ballerina/tests/fromXml_test.bal @@ -313,7 +313,7 @@ type RecRest6 record {| int[]...; |}; -public function main() returns error? { +public function testXmlStringToRecord26() returns error? { string xmlStr = string ` 1 diff --git a/native/src/main/java/io/ballerina/stdlib/data/xml/XmlParser.java b/native/src/main/java/io/ballerina/stdlib/data/xml/XmlParser.java index eb38518..b6f4005 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/xml/XmlParser.java +++ b/native/src/main/java/io/ballerina/stdlib/data/xml/XmlParser.java @@ -233,7 +233,7 @@ private void readText(XMLStreamReader xmlStreamReader, XmlParserData xmlParserDa BString bText = StringUtils.fromString(text); String fieldName = currentField.getFieldName(); BString bFieldName = StringUtils.fromString(fieldName); - Type fieldType = currentField.getFieldType(); + Type fieldType = TypeUtils.getReferredType(currentField.getFieldType()); if (currentNode.containsKey(bFieldName)) { // Handle - James Clark if (!xmlParserData.siblings.get( @@ -285,7 +285,7 @@ private void handleContentFieldInRecordType(RecordType recordType, BString text, } } - Type restType = recordType.getRestFieldType(); + Type restType = TypeUtils.getReferredType(recordType.getRestFieldType()); if (restType == null) { return; } @@ -495,7 +495,7 @@ private BString readElementRest(XMLStreamReader xmlStreamReader, XmlParserData x String elemName = getElementName(xmlStreamReader); BString currentFieldName = StringUtils.fromString(elemName); String lastElement = getLastElementInSiblings(xmlParserData.siblings); - Type restType = xmlParserData.restTypes.peek(); + Type restType = TypeUtils.getReferredType(xmlParserData.restTypes.peek()); if (!xmlParserData.siblings.isEmpty() && lastElement != null && !xmlParserData.siblings.getOrDefault(lastElement, true)) { @@ -576,7 +576,7 @@ private void readTextRest(XMLStreamReader xmlStreamReader, BString currentFieldN } BString bText = StringUtils.fromString(text); - Type restType = xmlParserData.restTypes.peek(); + Type restType = TypeUtils.getReferredType(xmlParserData.restTypes.peek()); // TODO: James Clark if (currentNode.get(currentFieldName) instanceof BArray) { ((BArray) currentNode.get(currentFieldName)).append( @@ -637,9 +637,9 @@ private Map getAllFieldsInRecordType(RecordType recordType, XmlPa for (BString annotationKey : annotations.getKeys()) { String keyStr = annotationKey.getValue(); if (keyStr.contains(Constants.FIELD)) { - String elementName = keyStr.split("\\$field\\$\\.")[1].replaceAll("\\\\", ""); + String fieldName = keyStr.split("\\$field\\$\\.")[1].replaceAll("\\\\", ""); Map fieldAnnotation = (Map) annotations.get(annotationKey); - modifiedNames.put(elementName, getModifiedName(fieldAnnotation, elementName)); + modifiedNames.put(fieldName, getModifiedName(fieldAnnotation, fieldName)); } } @@ -742,7 +742,7 @@ private void handleAttributes(XMLStreamReader xmlStreamReader, XmlParserData xml private Optional handleRecordRestType(XmlParserData xmlParserData, XMLStreamReader xmlStreamReader) { xmlParserData.currentField = null; - Type restType = xmlParserData.restTypes.peek(); + Type restType = TypeUtils.getReferredType(xmlParserData.restTypes.peek()); int restTypeTag = restType.getTag(); String elementName = getElementName(xmlStreamReader); if (restTypeTag == TypeTags.RECORD_TYPE_TAG) {