Hi All,
I have developed one static dropdown with node name tabs order, as shown below
I have written below JAVA code.
*********************** TabOrderModel JAVA Class ***********************
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
public class TabOrderModel {
String tabsOrderEnabled;
JsonArray tabsOrder;
public String getTabsOrderEnabled() {
return tabsOrderEnabled;
}
public void setTabsOrderEnabled(String tabsOrderEnabled) {
this.tabsOrderEnabled = tabsOrderEnabled;
}
public JsonArray getTabsOrder() {
return tabsOrder;
}
public void setTabsOrder(JsonArray tabsOrder) {
this.tabsOrder = tabsOrder;
}
@Override
public String toString() {
return "TabOrderModel [tabsOrderEnabled =" + tabsOrderEnabled + ", tabsOrder=" + tabsOrder + " ]";
}
}
****************************** JsonUtility JAVA *************************
private static void setTabOrderDetails(Node masterNode, ResourceResolver resourceResolver,
TabOrderModel tabOrderModel) throws RepositoryException {
if (masterNode.hasProperty(Constants.TABS_ORDER)) {
Property TabOrderProperty = masterNode.getProperty("tabsOrder");
//logger.info("values for TabOrderProperty ====== " + TabOrderProperty);//property=tabsOrder = [{"tabName":"community.about.value"}, {"tabName":"leadership.label.value"}, {"tabName":"community.about.value"},
multiValueTabOrder(resourceResolver, tabOrderModel, TabOrderProperty);
}
}
private static void multiValueTabOrder(ResourceResolver resourceResolver,
TabOrderModel tabOrderModel, Property TabOrderProperty) throws RepositoryException {
if (TabOrderProperty.isMultiple()) {
JsonArray array = new JsonArray();
JsonParser jsonParser = new JsonParser();
javax.jcr.Value[] values = TabOrderProperty.getValues();
for (javax.jcr.Value value : values) {
String jsonObj = value.getString();
logger.info("jsonObj123 for taborder ====== " + jsonObj);
array.add(jsonObj);
}
tabOrderModel.setTabsOrder(array);
}
}
But my JSON is coming below
My requirement is that ONLY tabName Value should come like below highlighted in red color but it is coming like above.
"tabsOrderSection": {
"tabsOrderEnabled": "true",
"tabsOrder": [
"community.about.value",
"leadership.label.value",
"community.about.value",
"leadership.label.value"
]
}
Can anybody please let me know how can I show only value of tabname inside JSON ?
Thanks
Views
Replies
Total Likes
Hi @subnaik As you are returning the response via the servlet, the manipulation of the format required can be done in the business logic layer.
You can have the Json Array within the Json Object before returning it.
import org.json.*;
import java.util.*;
public class JSONArrayToJSONObjTest {
public static void main(String args[]) {
List<String> list = new ArrayList<String>();
list.add("community.about.value");
list.add("leadership.label.value");
list.add("community.about.value");
list.add("leadership.about.value");
JSONArray array = new JSONArray();
for(int i = 0; i < list.size(); i++) {
array.put(list.get(i));
}
JSONObject obj = new JSONObject();
try {
obj.put("tabsOrder", array);
} catch(JSONException e) {
e.printStackTrace();
}
System.out.println(obj.toString());
}
}
Hope this helps!
Thanks
Thanks for your reply but here my requirement is that only my value for tabName node dropdown should come like below
community.about.value
Not like both dropdown node name and value will come like below.
tabName : community.about.value
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies