use of org.apache.geode.management.internal.cli.json.GfJsonObject in project geode by apache.
the class JsonUtil method getSet.
public static Set<CliJsonSerializable> getSet(GfJsonObject jsonObject, String byName) {
Set<CliJsonSerializable> cliJsonSerializables = Collections.emptySet();
try {
GfJsonArray cliJsonSerializableArray = jsonObject.getJSONArray(byName);
int size = cliJsonSerializableArray.size();
if (size > 0) {
cliJsonSerializables = new HashSet<CliJsonSerializable>();
}
for (int i = 0; i < size; i++) {
GfJsonObject cliJsonSerializableState = cliJsonSerializableArray.getJSONObject(i);
int jsId = cliJsonSerializableState.getInt(CliJsonSerializable.JSID);
CliJsonSerializable cliJsonSerializable = CliJsonSerializableFactory.getCliJsonSerializable(jsId);
cliJsonSerializable.fromJson(cliJsonSerializableState);
cliJsonSerializables.add(cliJsonSerializable);
}
} catch (GfJsonException e) {
throw new ResultDataException(e.getMessage());
}
return cliJsonSerializables;
}
use of org.apache.geode.management.internal.cli.json.GfJsonObject in project geode by apache.
the class JsonUtil method jsonToObject.
public static Object jsonToObject(String jsonString) {
Object objectFromJson = null;
try {
GfJsonObject jsonObject = new GfJsonObject(jsonString);
Iterator<String> keys = jsonObject.keys();
Object[] arr = new Object[jsonObject.size()];
int i = 0;
while (keys.hasNext()) {
String key = keys.next();
Class<?> klass = ClassPathLoader.getLatest().forName(key);
arr[i++] = jsonToObject((String) jsonObject.get(key).toString(), klass);
}
if (arr.length == 1) {
objectFromJson = arr[0];
} else {
objectFromJson = arr;
}
} catch (GfJsonException e) {
throw new IllegalArgumentException("Couldn't convert JSON to Object.", e);
} catch (ClassNotFoundException e) {
throw new IllegalArgumentException("Couldn't convert JSON to Object.", e);
}
return objectFromJson;
}
use of org.apache.geode.management.internal.cli.json.GfJsonObject in project geode by apache.
the class CommandResult method buildComposite.
/* private */
void buildComposite() {
try {
GfJsonObject content = getContent();
if (content != null) {
Table resultTable = TableBuilder.newTable();
resultTable.setColumnSeparator(" : ");
addHeaderInTable(resultTable, getGfJsonObject());
for (Iterator<String> it = content.keys(); it.hasNext(); ) {
String key = it.next();
if (key.startsWith(CompositeResultData.SECTION_DATA_ACCESSOR)) {
GfJsonObject subSection = content.getJSONObject(key);
buildSection(resultTable, null, subSection, 0);
} else if (key.equals(CompositeResultData.SEPARATOR)) {
String separatorString = content.getString(key);
resultTable.newRowGroup().newRowSeparator(separatorString.charAt(0), true);
}
}
addFooterInTable(resultTable, getGfJsonObject());
resultLines.addAll(resultTable.buildTableList());
}
} catch (GfJsonException e) {
resultLines.add("Error occurred while processing Command Result. Internal Error - Invalid Result.");
LogWrapper.getInstance().info("Error occurred while processing Command Result. Internal Error - Invalid Result.", e);
} finally {
isDataBuilt = true;
}
}
use of org.apache.geode.management.internal.cli.json.GfJsonObject in project geode by apache.
the class CompositeResultData method addSection.
public SectionResultData addSection(String keyToAccess) {
GfJsonObject sectionData = new GfJsonObject();
try {
contentObject.putAsJSONObject(SectionResultData.generateSectionKey(keyToAccess), sectionData);
} catch (GfJsonException e) {
throw new ResultDataException(e.getMessage());
}
subsectionCount++;
return new SectionResultData(sectionData);
}
use of org.apache.geode.management.internal.cli.json.GfJsonObject in project geode by apache.
the class CompositeResultData method addSection.
public SectionResultData addSection(SectionResultData otherSection) {
String keyToAccess = String.valueOf(subsectionCount);
GfJsonObject sectionData = otherSection.getSectionGfJsonObject();
try {
contentObject.putAsJSONObject(SectionResultData.generateSectionKey(keyToAccess), sectionData);
} catch (GfJsonException e) {
throw new ResultDataException(e.getMessage());
}
subsectionCount++;
return new SectionResultData(sectionData);
}
Aggregations