Fix adding null json values (#818)
This commit is contained in:
parent
5db3820df4
commit
1689a8abe2
@ -27,6 +27,7 @@ package me.lucko.luckperms.common.utils.gson;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonNull;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
@ -40,17 +41,26 @@ public class JArray implements JElement {
|
||||
return this.array;
|
||||
}
|
||||
|
||||
public JArray add(String value) {
|
||||
this.array.add(new JsonPrimitive(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
public JArray add(JsonElement value) {
|
||||
if (value == null) {
|
||||
return add(JsonNull.INSTANCE);
|
||||
}
|
||||
this.array.add(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public JArray add(String value) {
|
||||
if (value == null) {
|
||||
return add(JsonNull.INSTANCE);
|
||||
}
|
||||
this.array.add(new JsonPrimitive(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
public JArray add(JElement value) {
|
||||
if (value == null) {
|
||||
return add(JsonNull.INSTANCE);
|
||||
}
|
||||
return add(value.toJson());
|
||||
}
|
||||
|
||||
|
@ -26,6 +26,7 @@
|
||||
package me.lucko.luckperms.common.utils.gson;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonNull;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
|
||||
@ -46,18 +47,30 @@ public class JObject implements JElement {
|
||||
}
|
||||
|
||||
public JObject add(String key, String value) {
|
||||
if (value == null) {
|
||||
return add(key, JsonNull.INSTANCE);
|
||||
}
|
||||
return add(key, new JsonPrimitive(value));
|
||||
}
|
||||
|
||||
public JObject add(String key, Number value) {
|
||||
if (value == null) {
|
||||
return add(key, JsonNull.INSTANCE);
|
||||
}
|
||||
return add(key, new JsonPrimitive(value));
|
||||
}
|
||||
|
||||
public JObject add(String key, Boolean value) {
|
||||
if (value == null) {
|
||||
return add(key, JsonNull.INSTANCE);
|
||||
}
|
||||
return add(key, new JsonPrimitive(value));
|
||||
}
|
||||
|
||||
public JObject add(String key, JElement value) {
|
||||
if (value == null) {
|
||||
return add(key, JsonNull.INSTANCE);
|
||||
}
|
||||
return add(key, value.toJson());
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user