Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Want to see what's currently in public preview? We've pulled it all together in one place. Check it out here
cancel
Showing results for 
Search instead for 
Did you mean: 
pthomas
Contributor III
Contributor III

Passing json to tJava

I have a valid chunk of json from a tMap and the chunk is named "children."  I am trying to pass that into a tJava component.  The job won't even compile.  I get the error...

"Type mismatch: cannot convert from JSONArray to childrenStruct."

 

JSONObject currentNode = (JSONObject) globalMap.get("children");
 
JSONArray children = new JSONArray();
 
Stack<JSONArray> stack = new Stack<>();
 
if (currentNode.has("relationshipList")) {
stack.push(currentNode.getJSONArray("relationshipList"));
}
 
while (!stack.isEmpty()) {
JSONArray list = stack.pop();
 
for (int i=0; i<list.length(); i++) {
JSONObject currentChildNode = list.getJSONObject(i);
 
if (currentChildNode.has("unit")) {
JSONObject unit = currentChildNode.getJSONObject("unit");
 
if(currentChildNode.has("parentID")) {
unit.put("parentID", currentChildNode.getString("parentID"));
}
if(currentChildNode.has("level")) {
unit.put("level", currentChildNode.getString("level"));
}
}
 
children.put(unit);
}
 
if(currentChildNode.has("relationshipList")){
stack.push(currentChildNode.getJSONArray("relationshipList"));
}
}
 
globalMap.put("allSubordinates", children);
 
JSONArray retrievedList = (JSONArray) globalMap.get("allSubordinates");

 

 

 

Labels (4)
1 Solution

Accepted Solutions
Shicong_Hong
Employee
Employee

Hello @pthomas 

Check this article  https://community.qlik.com/t5/Official-Support-Articles/What-is-the-difference-between-tJava-tJavaRo...

I think you should use tJavaRow instead of tJava component in this case.

Regards

Shicong

View solution in original post

3 Replies
Shicong_Hong
Employee
Employee

Hello @pthomas 

Check this article  https://community.qlik.com/t5/Official-Support-Articles/What-is-the-difference-between-tJava-tJavaRo...

I think you should use tJavaRow instead of tJava component in this case.

Regards

Shicong

pthomas
Contributor III
Contributor III
Author

@Shicong_Hong - tJavaRow worked.  

I can't get to the article in your link though.

Shicong_Hong
Employee
Employee

I'm glad you got it working! I have corrected the article link, thanks for pointing it out.