From 82d83fe13a1f164021329dbd17e2625e684cc93a Mon Sep 17 00:00:00 2001 From: kirilldev Date: Sat, 2 Jan 2016 23:37:04 +0300 Subject: [PATCH] Added few handy methods (smth like "builder pattern"). --- json-smart/pom.xml | 2 +- .../src/main/java/net/minidev/json/JSONArray.java | 12 ++++++++++++ .../src/main/java/net/minidev/json/JSONObject.java | 13 +++++++++++++ parent/pom.xml | 2 +- 4 files changed, 27 insertions(+), 2 deletions(-) diff --git a/json-smart/pom.xml b/json-smart/pom.xml index 6f8ef20..089226e 100644 --- a/json-smart/pom.xml +++ b/json-smart/pom.xml @@ -3,7 +3,7 @@ 4.0.0 net.minidev json-smart - 2.2.1 + 2.2.2-SNAPSHOT JSON Small and Fast Parser JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write. It is easy for machines to parse and generate. It is based on a subset of the JavaScript Programming Language, Standard ECMA-262 3rd Edition - December 1999. JSON is a text format that is completely language independent but uses conventions that are familiar to programmers of the C-family of languages, including C, C++, C#, Java, JavaScript, Perl, Python, and many others. These properties make JSON an ideal data-interchange language. 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 * diff --git a/parent/pom.xml b/parent/pom.xml index 8b66677..1cac51b 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -3,7 +3,7 @@ 4.0.0 net.minidev minidev-parent - 2.2.1 + 2.2.2-SNAPSHOT Minidev super pom minidev common properties. pom