final GfJsonObject gfJsonObject = new GfJsonObject(json); final Status status = Status.valueOfDescription(gfJsonObject.getString(JSON_STATUS)); final List<String> jvmArguments = Arrays.asList(GfJsonArray.toStringArray(gfJsonObject.getJSONArray( JSON_JVMARGUMENTS))); gfJsonObject.getString(JSON_STATUSMESSAGE), gfJsonObject.getLong(JSON_TIMESTAMP), gfJsonObject.getString(JSON_LOCATION), gfJsonObject.getInt(JSON_PID), gfJsonObject.getLong(JSON_UPTIME), gfJsonObject.getString(JSON_WORKINGDIRECTORY), jvmArguments, gfJsonObject.getString(JSON_CLASSPATH), gfJsonObject.getString(JSON_GEMFIREVERSION), gfJsonObject.getString(JSON_JAVAVERSION), gfJsonObject.getString(JSON_LOGFILE), gfJsonObject.getString(JSON_HOST), gfJsonObject.getString(JSON_PORT), gfJsonObject.getString(JSON_MEMBERNAME));
public int getErrorCode(int errorCode) { return (Integer) contentObject.get(ERROR_CODE); }
/** * Converts given Map in to a JSON string representing a Map. * Refer http://www.json.org/ for more. * * @param properties a Map of Strings to be converted in to JSON String * @return a JSON string representing the specified Map. */ public static String mapToJson(Map<String, String> properties) { return new GfJsonObject(properties).toString(); }
public Data(GfJsonObject dataJsonObject) { this.header = dataJsonObject.getString("header"); this.content = dataJsonObject.getJSONObject("content"); this.footer = dataJsonObject.getString("footer"); }
protected AbstractResultData() { gfJsonObject = new GfJsonObject(); contentObject = new GfJsonObject(); try { gfJsonObject.putOpt(RESULT_CONTENT, contentObject); } catch (GfJsonException ignorable) { //ignorable as key won't be null here & it's thrown for ignorable values } }
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; }
private static String objectToJsonNestedChkCDep(Object object, int length, boolean checkCyclicDep) { GfJsonObject jsonObject = new GfJsonObject(object,checkCyclicDep); Iterator<String> iterator = jsonObject.keys(); while(iterator.hasNext()){ String key = iterator.next(); Object value = jsonObject.get(key); if(value!=null && !isPrimitiveOrWrapper(value.getClass())){ GfJsonObject jsonified = new GfJsonObject(value); String stringified = jsonified.toString(); try{ if(stringified.length()>length){ jsonObject.put(key,jsonified.getType()); }else{ jsonObject.put(key, stringified); } }catch (GfJsonException e) { e.printStackTrace(); } } } return jsonObject.toString(); }
array[1] = str; }else{ GfJsonObject object = new GfJsonObject(obj,true); Iterator keysIterator = object.keys(); while(keysIterator.hasNext()){ String key = (String) keysIterator.next(); Object value = object.get(key); if(GfJsonObject.isJSONKind(value)) { GfJsonObject jsonVal = new GfJsonObject(value); if (jsonVal.has("type-class")) { object.put(key, jsonVal.get("type-class")); } else { object.put(key, "a Map"); object.put(key, "a Collection"); } catch (GfJsonException e) { throw new RuntimeException(e); String str =object.toString(); array[1] = str;
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; }
private void buildSection(Table table, RowGroup parentRowGroup, GfJsonObject section, int depth) throws GfJsonException { Iterator<String> keys = section.keys(); RowGroup rowGroup = null; if (parentRowGroup != null) { while (keys.hasNext()) { String key = keys.next(); Object object = section.get(key); GfJsonObject tableObject = section.getJSONObject(key); buildTable(rowGroupForTable, tableObject.getJSONObject(ResultData.RESULT_CONTENT)); GfJsonObject subSection = section.getJSONObject(key); buildSection(table, rowGroup, subSection, depth + 1); } else if (key.equals(CompositeResultData.SEPARATOR)) { String separatorString = section.getString(key); rowGroup.newRowSeparator(separatorString.charAt(0), true); } else if (key.equals(ResultData.RESULT_HEADER) || key.equals(ResultData.RESULT_FOOTER)) {
CommandResponse(GfJsonObject jsonObject) { this.sender = jsonObject.getString("sender"); this.contentType = jsonObject.getString("contentType"); this.status = jsonObject.getInt("status"); this.page = jsonObject.getString("page"); this.tokenAccessor = jsonObject.getString("tokenAccessor"); this.debugInfo = jsonObject.getString("debugInfo"); this.data = new Data(jsonObject.getJSONObject("data")); this.when = jsonObject.getString("when"); this.version = jsonObject.getString("version"); this.failedToPersist = jsonObject.getBoolean("failedToPersist"); }
private void buildInfoErrorData(RowGroup rowGroup, GfJsonObject content) throws GfJsonException { GfJsonArray accumulatedData = content.getJSONArray(InfoResultData.RESULT_CONTENT_MESSAGE); if (accumulatedData != null) { buildRows(rowGroup, null, accumulatedData); } }
newString = sb.toString(); jsonObject = new GfJsonObject(newString); } else { jsonObject = new GfJsonObject(object); Iterator<String> keys = jsonObject.keys(); while (keys.hasNext()) { String k = keys.next(); Object value = jsonObject.get(k); if (value != null){
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); }
CommandResponse(GfJsonObject jsonObject) { this.sender = jsonObject.getString("sender"); this.contentType = jsonObject.getString("contentType"); this.status = jsonObject.getInt("status"); this.page = jsonObject.getString("page"); this.tokenAccessor = jsonObject.getString("tokenAccessor"); this.debugInfo = jsonObject.getString("debugInfo"); this.data = new Data(jsonObject.getJSONObject("data")); this.when = jsonObject.getString("when"); this.version = jsonObject.getString("version"); }
private static String pdxToJson(PdxInstance obj) { if(obj!=null){ try{ GfJsonObject json = new GfJsonObject(); for(String field : obj.getFieldNames()){ Object fieldValue = obj.getField(field); if(fieldValue!=null){ if(JsonUtil.isPrimitiveOrWrapper(fieldValue.getClass())){ json.put(field, fieldValue); }else{ json.put(field, fieldValue.getClass()); } } } return json.toString(); }catch(GfJsonException e){ return null; } } return null; }
@Override public String getHeader() { return gfJsonObject.getString(RESULT_HEADER); }
public GfJsonObject putAsJSONObject(String key, Object value) throws GfJsonException { try { Object internalJsonObj = extractInternalForGfJsonOrReturnSame(value); if (internalJsonObj == value) { GfJsonObject jsonObj = new GfJsonObject(value); internalJsonObj = jsonObj.getInternalJsonObject(); } jsonObject.put(key, internalJsonObj); } catch (JSONException e) { throw new GfJsonException(e.getMessage()); } return this; }
public String toString() { return gFJsonObject.toString(); }
public void checkResult(TypedJson tjson){ GfJsonObject gfJsonObj; try { gfJsonObj = new GfJsonObject(tjson.toString()); System.out.println(gfJsonObj); assertNotNull(gfJsonObj.get(RESULT)); } catch (GfJsonException e) { fail("Result could not be found"); } }