Fix compat with older Gson versions (#791)

This commit is contained in:
Luck 2018-02-24 13:50:38 +00:00
parent 68dd96e563
commit b2175e885f
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
2 changed files with 15 additions and 16 deletions

View File

@ -27,6 +27,7 @@ package me.lucko.luckperms.common.utils.gson;
import com.google.gson.JsonArray; import com.google.gson.JsonArray;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.google.gson.JsonPrimitive;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.function.Supplier; import java.util.function.Supplier;
@ -40,7 +41,7 @@ public class JArray implements JElement {
} }
public JArray add(String value) { public JArray add(String value) {
this.array.add(value); this.array.add(new JsonPrimitive(value));
return this; return this;
} }

View File

@ -27,6 +27,7 @@ package me.lucko.luckperms.common.utils.gson;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.function.Supplier; import java.util.function.Supplier;
@ -39,26 +40,23 @@ public class JObject implements JElement {
return this.object; return this.object;
} }
public JObject add(String key, String value) {
this.object.addProperty(key, value);
return this;
}
public JObject add(String key, Number value) {
this.object.addProperty(key, value);
return this;
}
public JObject add(String key, Boolean value) {
this.object.addProperty(key, value);
return this;
}
public JObject add(String key, JsonElement value) { public JObject add(String key, JsonElement value) {
this.object.add(key, value); this.object.add(key, value);
return this; return this;
} }
public JObject add(String key, String value) {
return add(key, new JsonPrimitive(value));
}
public JObject add(String key, Number value) {
return add(key, new JsonPrimitive(value));
}
public JObject add(String key, Boolean value) {
return add(key, new JsonPrimitive(value));
}
public JObject add(String key, JElement value) { public JObject add(String key, JElement value) {
return add(key, value.toJson()); return add(key, value.toJson());
} }