diff --git a/json-smart/pom.xml b/json-smart/pom.xml index f3f4710..7589afb 100644 --- a/json-smart/pom.xml +++ b/json-smart/pom.xml @@ -260,4 +260,4 @@ - \ No newline at end of file + diff --git a/json-smart/src/main/java/net/minidev/json/JSONArray.java b/json-smart/src/main/java/net/minidev/json/JSONArray.java index 350d491..a8b6344 100644 --- a/json-smart/src/main/java/net/minidev/json/JSONArray.java +++ b/json-smart/src/main/java/net/minidev/json/JSONArray.java @@ -79,6 +79,18 @@ public static void writeJSONString(List list, Appendable out) writeJSONString(list, out, JSONValue.COMPRESSION); } + /** + * Appends the specified element and returns this. + * Handy alternative to add(E e) method. + * + * @param element element to be appended to this array. + * @return this + */ + public JSONArray appendElement(Object element) { + add(element); + return this; + } + public void merge(Object o2) { JSONObject.merge(this, o2); } diff --git a/json-smart/src/main/java/net/minidev/json/JSONObject.java b/json-smart/src/main/java/net/minidev/json/JSONObject.java index e9ae547..ddf0d3b 100644 --- a/json-smart/src/main/java/net/minidev/json/JSONObject.java +++ b/json-smart/src/main/java/net/minidev/json/JSONObject.java @@ -98,6 +98,19 @@ else if (!compression.mustProtectKey(key)) JSONValue.writeJSONString(value, out, compression); } + /** + * Puts value to object and returns this. + * Handy alternative to put(String key, Object value) method. + * + * @param fieldName key with which the specified value is to be associated + * @param fieldValue value to be associated with the specified key + * @return this + */ + public JSONObject appendField(String fieldName, Object fieldValue) { + put(fieldName, fieldValue); + return this; + } + /** * A Simple Helper object to String *