Hi All, Regarding the jira [1]. In DSS when using json output mapping we can filter out the output fields according to the person's role who invokes the service. If he have permission, those fields will be visible to them. If he doesn't have permission, only other fields will be visible to him. This is explained in [2]
But as the jira says, this feature doesn't work in standalone pack. In wsdl file of the data service, these fields are marked as optional by adding 'minOccurs="0"' attribute. But the "GsonXMLStreamWriter.java" class in "axis2-json" module doesn't consider this "minOccurs" attribute when converting the xml output to json. This causes the error mentioned in the jira [1]. I have changed the source to avoid this situation and consider the "minOccurs" attribute when doing the conversion part. Is this the better way of resolving this problem? If so please review the code and commit to kernel patch 009. [1] - https://wso2.org/jira/browse/DS-963 [2] - https://docs.wso2.com/display/DSS321/JSON+Mapping Thanks -- Rajith Vitharana Software Engineer, WSO2 Inc. : wso2.com Mobile : +94715883223 Blog : http://lankavitharana.blogspot.com/
Index: src/org/apache/axis2/json/gson/GsonXMLStreamWriter.java =================================================================== --- src/org/apache/axis2/json/gson/GsonXMLStreamWriter.java (revision 207496) +++ src/org/apache/axis2/json/gson/GsonXMLStreamWriter.java (working copy) @@ -208,6 +208,11 @@ if (miniStack.isEmpty()) { if (!queue.isEmpty()) { JsonObject queObj = queue.peek(); + if (!queObj.getName().equals(localName) && queObj.getMinOccurs() == 0 + && (stack.isEmpty() || !stack.peek().getName().equals(localName))){ + queue.poll(); + queObj = queue.peek(); + } if (queObj.getName().equals(localName)) { if (flushObject != null) { if (topNestedArrayObj != null && flushObject.getType() == JSONType.NESTED_ARRAY Index: src/org/apache/axis2/json/gson/factory/JsonObject.java =================================================================== --- src/org/apache/axis2/json/gson/factory/JsonObject.java (revision 207496) +++ src/org/apache/axis2/json/gson/factory/JsonObject.java (working copy) @@ -25,6 +25,7 @@ private JSONType type; private String valueType; private String namespaceUri; + private long minOccurs; public JsonObject(String name, JSONType type, String valueType , String namespaceUri) { this.name = name; @@ -48,4 +49,12 @@ public String getNamespaceUri() { return namespaceUri; } + + public void setMinOccurs(long minOccurs) { + this.minOccurs = minOccurs; + } + + public long getMinOccurs() { + return minOccurs; + } } Index: src/org/apache/axis2/json/gson/factory/XmlNode.java =================================================================== --- src/org/apache/axis2/json/gson/factory/XmlNode.java (revision 207496) +++ src/org/apache/axis2/json/gson/factory/XmlNode.java (working copy) @@ -30,6 +30,7 @@ private List<XmlNode> childrenList = new ArrayList<XmlNode>(); private String valueType; private String namespaceUri; + private long minOccurs; public XmlNode(String name,String namespaceUri, boolean attribute, boolean array , String valueType) { this.name = name; @@ -68,4 +69,12 @@ public String getNamespaceUri() { return namespaceUri; } + + public void setMinOccurs(long minOccurs) { + this.minOccurs = minOccurs; + } + + public long getMinOccurs() { + return minOccurs; + } } Index: src/org/apache/axis2/json/gson/factory/XmlNodeGenerator.java =================================================================== --- src/org/apache/axis2/json/gson/factory/XmlNodeGenerator.java (revision 207496) +++ src/org/apache/axis2/json/gson/factory/XmlNodeGenerator.java (working copy) @@ -90,6 +90,7 @@ QName refName = element.getRefName(); if (schemaTypeName != null) { xmlNode = new XmlNode(element.getName(), targetNamespace, false, (element.getMaxOccurs() != 1), schemaTypeName.getLocalPart()); + xmlNode.setMinOccurs(element.getMinOccurs()); parentNode.addChildToList(xmlNode); if (("http://www.w3.org/2001/XMLSchema").equals(schemaTypeName.getNamespaceURI())) { } else { @@ -106,6 +107,7 @@ } }else if (schemaType != null) { xmlNode = new XmlNode(element.getName(), targetNamespace, false, (element.getMaxOccurs() != 1), schemaType.getQName().getLocalPart()); + xmlNode.setMinOccurs(element.getMinOccurs()); parentNode.addChildToList(xmlNode); processSchemaType(schemaType, xmlNode, schema); }else if (refName != null) { @@ -175,17 +177,25 @@ private void generateQueue(XmlNode node) { if (node.isArray()) { if (node.getChildrenList().size() > 0) { - queue.add(new JsonObject(node.getName(), JSONType.NESTED_ARRAY, node.getValueType() , node.getNamespaceUri())); + JsonObject obj = new JsonObject(node.getName(), JSONType.NESTED_ARRAY, node.getValueType() , node.getNamespaceUri()); + obj.setMinOccurs(node.getMinOccurs()); + queue.add(obj); processXmlNodeChildren(node.getChildrenList()); } else { - queue.add(new JsonObject(node.getName(), JSONType.ARRAY , node.getValueType() , node.getNamespaceUri())); + JsonObject obj = new JsonObject(node.getName(), JSONType.ARRAY , node.getValueType() , node.getNamespaceUri()); + obj.setMinOccurs(node.getMinOccurs()); + queue.add(obj); } } else { if (node.getChildrenList().size() > 0) { - queue.add(new JsonObject(node.getName(), JSONType.NESTED_OBJECT, node.getValueType() , node.getNamespaceUri())); + JsonObject obj = new JsonObject(node.getName(), JSONType.NESTED_OBJECT, node.getValueType() , node.getNamespaceUri()); + obj.setMinOccurs(node.getMinOccurs()); + queue.add(obj); processXmlNodeChildren(node.getChildrenList()); } else { - queue.add(new JsonObject(node.getName(), JSONType.OBJECT , node.getValueType() , node.getNamespaceUri())); + JsonObject obj = new JsonObject(node.getName(), JSONType.OBJECT , node.getValueType() , node.getNamespaceUri()); + obj.setMinOccurs(node.getMinOccurs()); + queue.add(obj); } } }
_______________________________________________ Dev mailing list Dev@wso2.org http://wso2.org/cgi-bin/mailman/listinfo/dev