mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2026-11-20 06:29:40 +00:00
Fix adding null json values (#818)
This commit is contained in:
2 files changed
+28
-5
No files matched your search
@@ -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());
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user