Adding restrictions on the JsonElements to disallow Java "null"s.
This commit is contained in:
parent
10c39317a1
commit
93b0008486
|
@ -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.
|
* @param element the element that needs to be added to the array.
|
||||||
*/
|
*/
|
||||||
public void add(JsonElement element) {
|
public void add(JsonElement element) {
|
||||||
|
if (element == null) {
|
||||||
|
element = JsonNull.createJsonNull();
|
||||||
|
}
|
||||||
elements.add(element);
|
elements.add(element);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -53,6 +53,12 @@ public final class JsonObject extends JsonElement {
|
||||||
* @param value the member object.
|
* @param value the member object.
|
||||||
*/
|
*/
|
||||||
public void add(String property, JsonElement value) {
|
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);
|
members.put(property, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,7 @@ public final class JsonPrimitive extends JsonElement {
|
||||||
* @param bool the value to create the primitive with.
|
* @param bool the value to create the primitive with.
|
||||||
*/
|
*/
|
||||||
public JsonPrimitive(Boolean bool) {
|
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.
|
* @param number the value to create the primitive with.
|
||||||
*/
|
*/
|
||||||
public JsonPrimitive(Number number) {
|
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.
|
* @param string the value to create the primitive with.
|
||||||
*/
|
*/
|
||||||
public JsonPrimitive(String string) {
|
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.
|
* @param c the value to create the primitive with.
|
||||||
*/
|
*/
|
||||||
public JsonPrimitive(Character c) {
|
public JsonPrimitive(Character c) {
|
||||||
this.value = String.valueOf(c);
|
setValue(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue
Block a user