diff --git a/common/src/main/java/me/lucko/luckperms/common/utils/gson/JArray.java b/common/src/main/java/me/lucko/luckperms/common/utils/gson/JArray.java index 07bc59539..1aec11bb0 100644 --- a/common/src/main/java/me/lucko/luckperms/common/utils/gson/JArray.java +++ b/common/src/main/java/me/lucko/luckperms/common/utils/gson/JArray.java @@ -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()); } diff --git a/common/src/main/java/me/lucko/luckperms/common/utils/gson/JObject.java b/common/src/main/java/me/lucko/luckperms/common/utils/gson/JObject.java index e18823261..507417340 100644 --- a/common/src/main/java/me/lucko/luckperms/common/utils/gson/JObject.java +++ b/common/src/main/java/me/lucko/luckperms/common/utils/gson/JObject.java @@ -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()); }