Skip to content

Commit

Permalink
Updated JsonArray to support adding primitives directly via an overlo…
Browse files Browse the repository at this point in the history
…aded "add(...)" method rather than having to always do "add(new JsonPrimitive(...))"
  • Loading branch information
Dillon Dixon committed Jul 24, 2015
1 parent 31ea72a commit 6960ebc
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions gson/src/main/java/com/google/gson/JsonArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,54 @@ JsonArray deepCopy() {
return result;
}

/**
* Adds the specified boolean to self.
*
* @param bool the boolean that needs to be added to the array.
*/
public void add(Boolean bool) {
if (bool == null) {
elements.add(JsonNull.INSTANCE);
}
elements.add(new JsonPrimitive(bool));
}

/**
* Adds the specified character to self.
*
* @param character the character that needs to be added to the array.
*/
public void add(Character character) {
if (character == null) {
elements.add(JsonNull.INSTANCE);
}
elements.add(new JsonPrimitive(character));
}

/**
* Adds the specified number to self.
*
* @param number the number that needs to be added to the array.
*/
public void add(Number number) {
if (number == null) {
elements.add(JsonNull.INSTANCE);
}
elements.add(new JsonPrimitive(number));
}

/**
* Adds the specified string to self.
*
* @param string the string that needs to be added to the array.
*/
public void add(String string) {
if (string == null) {
elements.add(JsonNull.INSTANCE);
}
elements.add(new JsonPrimitive(string));
}

/**
* Adds the specified element to self.
*
Expand Down

0 comments on commit 6960ebc

Please sign in to comment.