/** * Make a prettyprinted JSON text of this JSONObject. * <p> * Warning: This method assumes that the data structure is acyclical. * @param indentFactor The number of spaces to add to each level of * indentation. * @return a printable, displayable, portable, transmittable * representation of the object, beginning * with <code>{</code> <small>(left brace)</small> and ending * with <code>}</code> <small>(right brace)</small>. * @throws JSONException If the object contains an invalid number. */ public String toString(final int indentFactor) throws JSONException { return toString(indentFactor, 0); }
/** * Make a prettyprinted JSON text of this JSONObject. * <p> * Warning: This method assumes that the data structure is acyclical. * @param indentFactor The number of spaces to add to each level of * indentation. * @return a printable, displayable, portable, transmittable * representation of the object, beginning * with <code>{</code> <small>(left brace)</small> and ending * with <code>}</code> <small>(right brace)</small>. * @throws JSONException If the object contains an invalid number. */ public String toString(final int indentFactor) throws JSONException { return toString(indentFactor, 0); }
public static String toJSon(final MessageCounter counter) throws Exception { DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM); JSONObject json = new JSONObject(counter); String lastAddTimestamp = dateFormat.format(new Date(counter.getLastAddedMessageTime())); json.put("lastAddTimestamp", lastAddTimestamp); String updateTimestamp = dateFormat.format(new Date(counter.getLastUpdate())); json.put("updateTimestamp", updateTimestamp); return json.toString(); }
/** * Returns a JSON String serialization of a {@link MessageCounter} object. * @param counter * @return * @throws Exception */ public static String toJSon(final MessageCounter counter) throws Exception { DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM); JSONObject json = new JSONObject(counter); String lastAddTimestamp = dateFormat.format(new Date(counter.getLastAddedMessageTime())); json.put("lastAddTimestamp", lastAddTimestamp); String updateTimestamp = dateFormat.format(new Date(counter.getLastUpdate())); json.put("updateTimestamp", updateTimestamp); return json.toString(); }
public String getAddressSettingsAsJSON(final String address) throws Exception { checkStarted(); AddressSettings addressSettings = server.getAddressSettingsRepository().getMatch(address); Map<String, Object> settings = new HashMap<String, Object>(); if (addressSettings.getDeadLetterAddress() != null) { settings.put("DLA", addressSettings.getDeadLetterAddress()); } if (addressSettings.getExpiryAddress() != null) { settings.put("expiryAddress", addressSettings.getExpiryAddress()); } settings.put("maxDeliveryAttempts", addressSettings.getMaxDeliveryAttempts()); settings.put("pageCacheMaxSize", addressSettings.getPageCacheMaxSize()); settings.put("maxSizeBytes", addressSettings.getMaxSizeBytes()); settings.put("pageSizeBytes", addressSettings.getPageSizeBytes()); settings.put("redeliveryDelay", addressSettings.getRedeliveryDelay()); settings.put("redistributionDelay", addressSettings.getRedistributionDelay()); settings.put("lastValueQueue", addressSettings.isLastValueQueue()); settings.put("sendToDLAOnNoRoute", addressSettings.isSendToDLAOnNoRoute()); String policy = addressSettings.getAddressFullMessagePolicy() == AddressFullMessagePolicy.PAGE ? "PAGE" : addressSettings.getAddressFullMessagePolicy() == AddressFullMessagePolicy.BLOCK ? "BLOCK" : "DROP"; settings.put("addressFullMessagePolicy", policy); JSONObject jsonObject = new JSONObject(settings); return jsonObject.toString(); }
return jsonObject.toString();
public static String toJSON(final DayCounterInfo[] infos) throws JSONException { JSONObject json = new JSONObject(); JSONArray counters = new JSONArray(); for (DayCounterInfo info : infos) { JSONObject counter = new JSONObject(); counter.put("date", info.getDate()); counter.put("counters", Arrays.asList(info.getCounters())); counters.put(counter); } json.put("dayCounters", counters); return json.toString(); }
public static String toJSON(final DayCounterInfo[] infos) throws JSONException { JSONObject json = new JSONObject(); JSONArray counters = new JSONArray(); for (DayCounterInfo info : infos) { JSONObject counter = new JSONObject(); counter.put("date", info.getDate()); counter.put("counters", Arrays.asList(info.getCounters())); counters.put(counter); } json.put("dayCounters", counters); return json.toString(); }
return new JSONObject((Map)value).toString();
return new JSONObject((Map)value).toString();