Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added few handy methods (smth like "builder pattern"). #21

Merged
merged 1 commit into from
Sep 24, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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