public GfJsonObject put(String key, Map<?, ?> value) throws GfJsonException { try { jsonObject.put(key, value); } catch (JSONException e) { throw new GfJsonException(e.getMessage()); } return this; }
/** * * @param indentFactor * @return this GfJsonObject * @throws GfJsonException * If the object contains an invalid number. */ public String toIndentedString(int indentFactor) throws GfJsonException { try { return jsonObject.toString(indentFactor); } catch (JSONException e) { throw new GfJsonException(e.getMessage()); } }
public GfJsonObject put(String key, Map<?, ?> value) throws GfJsonException { try { jsonObject.put(key, value); } catch (JSONException e) { throw new GfJsonException(e.getMessage()); } return this; }
/** * * @param source * @throws GfJsonException If there is a syntax error. */ public GfJsonArray(String source) throws GfJsonException { try { this.jsonArray = new JSONArray(source); } catch (JSONException e) { throw new GfJsonException(e.getMessage()); } }
/** * * @param source * @throws GfJsonException If there is a syntax error. */ public GfJsonArray(String source) throws GfJsonException { try { this.jsonArray = new JSONArray(source); } catch (JSONException e) { throw new GfJsonException(e.getMessage()); } }
/** * * @param indentFactor * @return this GfJsonArray * @throws GfJsonException * If the object contains an invalid number. */ public String toIndentedString(int indentFactor) throws GfJsonException { try { return jsonArray.toString(indentFactor); } catch (JSONException e) { throw new GfJsonException(e.getMessage()); } }
/** * * @param source * A string beginning with { (left brace) and ending with } (right * brace). * @throws GfJsonException * - If there is a syntax error in the source string or a duplicated * key. */ public GfJsonObject(String source) throws GfJsonException { try { this.jsonObject = new JSONObject(source); } catch (JSONException e) { throw new GfJsonException(e.getMessage()); } }
/** * Get the object value associated with an index. * * @param index * @return An object value. * @throws GfJsonException If there is no value for the index. */ public Object get(int index) throws GfJsonException { try { return this.jsonArray.get(index); } catch (JSONException e) { throw new GfJsonException(e.getMessage()); } }
/** * * @param indentFactor * @return this GfJsonArray * @throws GfJsonException * If the object contains an invalid number. */ public String toIndentedString(int indentFactor) throws GfJsonException { try { return jsonArray.toString(indentFactor); } catch (JSONException e) { throw new GfJsonException(e.getMessage()); } }
/** * Get the object value associated with an index. * * @param index * @return An object value. * @throws GfJsonException If there is no value for the index. */ public Object get(int index) throws GfJsonException { try { return this.jsonArray.get(index); } catch (JSONException e) { throw new GfJsonException(e.getMessage()); } }
/** * * @param indentFactor * @return this GfJsonObject * @throws GfJsonException * If the object contains an invalid number. */ public String toIndentedString(int indentFactor) throws GfJsonException { try { return jsonObject.toString(indentFactor); } catch (JSONException e) { throw new GfJsonException(e.getMessage()); } }
private static Object toList(Object value, Class<?> parameterType) throws GfJsonException { try { JSONArray array = (JSONArray) value; List list = new ArrayList(); for (int i = 0; i < array.length(); i++) { Object element = array.get(i); if(isPrimitiveOrWrapper(element.getClass())){ list.add(element); } else throw new GfJsonException("Only primitive types are supported in set type for input commands"); } return list; } catch (JSONException e) { throw new GfJsonException(e); } }
public GfJsonObject getJSONObject(int index) throws GfJsonException { try { return new GfJsonObject(jsonArray.getJSONObject(index)); } catch (JSONException e) { throw new GfJsonException(e.getMessage()); } }
public GfJsonObject getJSONObject(int index) throws GfJsonException { try { return new GfJsonObject(jsonArray.getJSONObject(index)); } catch (JSONException e) { throw new GfJsonException(e.getMessage()); } }
public GfJsonObject accumulateAsJSONObject(String key, Object value) throws GfJsonException { JSONObject val = new JSONObject(value); try { if (jsonObject.has(key)) { jsonObject.append(key, val); } else { //first time always add JSONArray for accumulate - for convenience jsonObject.put(key, new JSONArray().put(val)); } } catch (JSONException e) { throw new GfJsonException(e.getMessage()); } return this; }
public GfJsonObject accumulateAsJSONObject(String key, Object value) throws GfJsonException { JSONObject val = new JSONObject(value); try { if (jsonObject.has(key)) { jsonObject.append(key, val); } else { //first time always add JSONArray for accumulate - for convenience jsonObject.put(key, new JSONArray().put(val)); } } catch (JSONException e) { throw new GfJsonException(e.getMessage()); } return this; }
public GfJsonObject putJSONArray(String key, GfJsonArray value) throws GfJsonException { try { jsonObject.putOpt(key, value.getInternalJsonArray()); } catch (JSONException e) { throw new GfJsonException(e.getMessage()); } return this; }
public GfJsonObject putJSONArray(String key, GfJsonArray value) throws GfJsonException { try { jsonObject.putOpt(key, value.getInternalJsonArray()); } catch (JSONException e) { throw new GfJsonException(e.getMessage()); } return this; }
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 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; }