Skip to content

Commit

Permalink
Handle reference type properly
Browse files Browse the repository at this point in the history
  • Loading branch information
prakanth97 committed Oct 30, 2023
1 parent 2f212f3 commit b9494e1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion ballerina/tests/fromXml_test.bal
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ type RecRest6 record {|
int[]...;
|};

public function main() returns error? {
public function testXmlStringToRecord26() returns error? {
string xmlStr = string `
<Data>
<A>1</A>
Expand Down
14 changes: 7 additions & 7 deletions native/src/main/java/io/ballerina/stdlib/data/xml/XmlParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 - <name>James <!-- FirstName --> Clark</name>
if (!xmlParserData.siblings.get(
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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: <name>James <!-- FirstName --> Clark</name>
if (currentNode.get(currentFieldName) instanceof BArray) {
((BArray) currentNode.get(currentFieldName)).append(
Expand Down Expand Up @@ -637,9 +637,9 @@ private Map<String, Field> 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<BString, Object> fieldAnnotation = (Map<BString, Object>) annotations.get(annotationKey);
modifiedNames.put(elementName, getModifiedName(fieldAnnotation, elementName));
modifiedNames.put(fieldName, getModifiedName(fieldAnnotation, fieldName));
}
}

Expand Down Expand Up @@ -742,7 +742,7 @@ private void handleAttributes(XMLStreamReader xmlStreamReader, XmlParserData xml

private Optional<Object> 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) {
Expand Down

0 comments on commit b9494e1

Please sign in to comment.