Skip to content

Commit

Permalink
Added few handy methods (smth like "builder pattern").
Browse files Browse the repository at this point in the history
  • Loading branch information
kirilldev committed Jan 2, 2016
1 parent cb03bcb commit 82d83fe
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
2 changes: 1 addition & 1 deletion json-smart/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>net.minidev</groupId>
<artifactId>json-smart</artifactId>
<version>2.2.1</version>
<version>2.2.2-SNAPSHOT</version>
<name>JSON Small and Fast Parser</name>
<description>
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.
Expand Down
12 changes: 12 additions & 0 deletions json-smart/src/main/java/net/minidev/json/JSONArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,18 @@ public static void writeJSONString(List<? extends Object> 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);
}
Expand Down
13 changes: 13 additions & 0 deletions json-smart/src/main/java/net/minidev/json/JSONObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
2 changes: 1 addition & 1 deletion parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>net.minidev</groupId>
<artifactId>minidev-parent</artifactId>
<version>2.2.1</version>
<version>2.2.2-SNAPSHOT</version>
<name>Minidev super pom</name>
<description>minidev common properties.</description>
<packaging>pom</packaging>
Expand Down

0 comments on commit 82d83fe

Please sign in to comment.