Adding restrictions on the JsonElements to disallow Java "null"s.

This commit is contained in:
Joel Leitch 2009-10-08 22:03:08 +00:00
parent 10c39317a1
commit 93b0008486
3 changed files with 73 additions and 64 deletions

View File

@ -48,6 +48,9 @@ public final class JsonArray extends JsonElement implements Iterable<JsonElement
* @param element the element that needs to be added to the array.
*/
public void add(JsonElement element) {
if (element == null) {
element = JsonNull.createJsonNull();
}
elements.add(element);
}

View File

@ -53,6 +53,12 @@ public final class JsonObject extends JsonElement {
* @param value the member object.
*/
public void add(String property, JsonElement value) {
Preconditions.checkArgument(property != null && !"".equals(property.trim()));
Preconditions.checkNotNull(property);
if (value == null) {
value = JsonNull.createJsonNull();
}
members.put(property, value);
}

View File

@ -44,7 +44,7 @@ public final class JsonPrimitive extends JsonElement {
* @param bool the value to create the primitive with.
*/
public JsonPrimitive(Boolean bool) {
this.value = bool;
setValue(bool);
}
/**
@ -53,7 +53,7 @@ public final class JsonPrimitive extends JsonElement {
* @param number the value to create the primitive with.
*/
public JsonPrimitive(Number number) {
this.value = number;
setValue(number);
}
/**
@ -62,7 +62,7 @@ public final class JsonPrimitive extends JsonElement {
* @param string the value to create the primitive with.
*/
public JsonPrimitive(String string) {
this.value = string;
setValue(string);
}
/**
@ -72,7 +72,7 @@ public final class JsonPrimitive extends JsonElement {
* @param c the value to create the primitive with.
*/
public JsonPrimitive(Character c) {
this.value = String.valueOf(c);
setValue(c);
}
/**