From b2175e885f28e048af71c9653c01371a5e6819bb Mon Sep 17 00:00:00 2001 From: Luck Date: Sat, 24 Feb 2018 13:50:38 +0000 Subject: [PATCH] Fix compat with older Gson versions (#791) --- .../luckperms/common/utils/gson/JArray.java | 3 +- .../luckperms/common/utils/gson/JObject.java | 28 +++++++++---------- 2 files changed, 15 insertions(+), 16 deletions(-) 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 663298a10..07bc59539 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.JsonPrimitive; import java.util.function.Consumer; import java.util.function.Supplier; @@ -40,7 +41,7 @@ public class JArray implements JElement { } public JArray add(String value) { - this.array.add(value); + this.array.add(new JsonPrimitive(value)); return this; } 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 61977dbaf..e18823261 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 @@ -27,6 +27,7 @@ package me.lucko.luckperms.common.utils.gson; import com.google.gson.JsonElement; import com.google.gson.JsonObject; +import com.google.gson.JsonPrimitive; import java.util.function.Consumer; import java.util.function.Supplier; @@ -39,26 +40,23 @@ public class JObject implements JElement { 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) { this.object.add(key, value); 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) { return add(key, value.toJson()); }