-
Notifications
You must be signed in to change notification settings - Fork 32
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
Revamp native code #291
Revamp native code #291
Conversation
Codecov Report
@@ Coverage Diff @@
## master #291 +/- ##
============================================
+ Coverage 87.20% 88.05% +0.85%
+ Complexity 89 83 -6
============================================
Files 7 7
Lines 297 268 -29
Branches 64 56 -8
============================================
- Hits 259 236 -23
+ Misses 22 18 -4
+ Partials 16 14 -2
Continue to review full report at Codecov.
|
Marked as draft since the proposal acceptance is still under review |
List<BXml> newSequence = new ArrayList<BXml>(); | ||
for (BXml value: sequence) { | ||
String textValue = value.getTextValue(); | ||
if (textValue.isEmpty() || !textValue.trim().isEmpty()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What are we checking here ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When initialising xml with line break between elements, couldn't get the proper BXml list by using xmlSequence.getChildrenList(). This list contain line breaks as element. So I used this to eliminate line break. Now I have created issue for this. Please find the issue for this: ballerina-platform/ballerina-lang#33497
private static LinkedHashMap<String, String> attributeMap = new LinkedHashMap<>(); | ||
private static LinkedHashMap<String, String> tempAttributeMap = new LinkedHashMap<>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why static variables ? This is not concurrent safe.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is used in static method. Hence, I am using static variable. Now, I have changed LinkedHashMap to ConcurrentHashMap in 562a4dd.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code is not concurrent safe.
groups: ["toJson"] | ||
} | ||
isolated function testComplexXmlWithNamespace() returns error? { | ||
xml x1 = xml `<ns0:bookStore status="online" xmlns:ns0="http://sample.com/test"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAIK this is not a valid xml
(multiple possible root nodes) and therefore should return an error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is in the spec. So, I haven't checked whether this valid or not. Yes, This is not valid XML. We don't need to validate in the xmldata module. it should be validated in the lang lib. Did you create an issue for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Created an issue: ballerina-platform/ballerina-lang#33501
*/ | ||
public class AttributeManager { | ||
|
||
private ConcurrentHashMap<String, String> concurrentHashMap; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use LinkedHashMap here, since AttributeManager is concurrent safe now. Also we need to preserve the order, so replace other usages with LinkedHashMap as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 3481ab2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall design looks ok.
ballerina/tests/xml_to_json_test.bal
Outdated
"{\"StreetAddress\":\"20, Palm grove, Colombo 3\"}, \"\\n \", " + | ||
"{\"City\":\"Colombo\"}, \"\\n \", {\"Zip\":\"00300\"}, \"\\n \", " + | ||
"{\"Country\":\"LK\"}, \"\\n \"], \"@xmlns\":\"\"}, \"\\n \"], " + | ||
test:assertEquals(convertToJson(e.toString()),"{\"Invoice\":{\"PurchesedItems\":{\"PLine\":[" + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IINM convertToJson
is a test util function. Why are there unit tests for this function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had these as these test utils functions are keeping long times. But It seems these are not useful because the toJson() directly calls the convertToJSON(). We can test this by calling ballerina API. So, we don't need to test the convertToJSON() by using these test utils. So I have removed this util module in 873cc8c.
native/src/main/java/io/ballerina/stdlib/xmldata/XmlToJson.java
Outdated
Show resolved
Hide resolved
native/src/main/java/io/ballerina/stdlib/xmldata/XmlToJson.java
Outdated
Show resolved
Hide resolved
5855d71
to
873cc8c
Compare
Purpose
The toJson() has some gaps with spec. When analyzed the spec, the following gaps were identified:
Existing output:
Expected output:
Existing output:
If the key is missing in the XML, it has to take the key value as
#content
. But this is not implemented.Following issues have been reported by others
Getting child elements as an array in XML to JSON conversion
Getting the same element name twice in JSON output
Unable to remove all namespace in xml to json
So, this PR contains all these fixes.
Fixes: ballerina-platform/ballerina-library#2126
Examples
Checklist