Skip to content

Commit 82d83fe

Browse files
committed
Added few handy methods (smth like "builder pattern").
1 parent cb03bcb commit 82d83fe

File tree

4 files changed

+27
-2
lines changed

4 files changed

+27
-2
lines changed

json-smart/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>net.minidev</groupId>
55
<artifactId>json-smart</artifactId>
6-
<version>2.2.1</version>
6+
<version>2.2.2-SNAPSHOT</version>
77
<name>JSON Small and Fast Parser</name>
88
<description>
99
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.

json-smart/src/main/java/net/minidev/json/JSONArray.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,18 @@ public static void writeJSONString(List<? extends Object> list, Appendable out)
7979
writeJSONString(list, out, JSONValue.COMPRESSION);
8080
}
8181

82+
/**
83+
* Appends the specified element and returns this.
84+
* Handy alternative to add(E e) method.
85+
*
86+
* @param element element to be appended to this array.
87+
* @return this
88+
*/
89+
public JSONArray appendElement(Object element) {
90+
add(element);
91+
return this;
92+
}
93+
8294
public void merge(Object o2) {
8395
JSONObject.merge(this, o2);
8496
}

json-smart/src/main/java/net/minidev/json/JSONObject.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,19 @@ else if (!compression.mustProtectKey(key))
9898
JSONValue.writeJSONString(value, out, compression);
9999
}
100100

101+
/**
102+
* Puts value to object and returns this.
103+
* Handy alternative to put(String key, Object value) method.
104+
*
105+
* @param fieldName key with which the specified value is to be associated
106+
* @param fieldValue value to be associated with the specified key
107+
* @return this
108+
*/
109+
public JSONObject appendField(String fieldName, Object fieldValue) {
110+
put(fieldName, fieldValue);
111+
return this;
112+
}
113+
101114
/**
102115
* A Simple Helper object to String
103116
*

parent/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>net.minidev</groupId>
55
<artifactId>minidev-parent</artifactId>
6-
<version>2.2.1</version>
6+
<version>2.2.2-SNAPSHOT</version>
77
<name>Minidev super pom</name>
88
<description>minidev common properties.</description>
99
<packaging>pom</packaging>

0 commit comments

Comments
 (0)