Proper JsonPrimitive cloning
This commit is contained in:
parent
b7ff72fde2
commit
17fa7af792
@ -7,6 +7,7 @@ import com.massivecraft.massivecore.xlib.gson.JsonArray;
|
|||||||
import com.massivecraft.massivecore.xlib.gson.JsonElement;
|
import com.massivecraft.massivecore.xlib.gson.JsonElement;
|
||||||
import com.massivecraft.massivecore.xlib.gson.JsonNull;
|
import com.massivecraft.massivecore.xlib.gson.JsonNull;
|
||||||
import com.massivecraft.massivecore.xlib.gson.JsonObject;
|
import com.massivecraft.massivecore.xlib.gson.JsonObject;
|
||||||
|
import com.massivecraft.massivecore.xlib.gson.JsonPrimitive;
|
||||||
|
|
||||||
public class GsonCloner
|
public class GsonCloner
|
||||||
{
|
{
|
||||||
@ -21,9 +22,12 @@ public class GsonCloner
|
|||||||
// JsonPrimitive
|
// JsonPrimitive
|
||||||
if (element.isJsonPrimitive())
|
if (element.isJsonPrimitive())
|
||||||
{
|
{
|
||||||
// TODO: This is actually not safe since JsonPrimitive is mutable.
|
JsonPrimitive primitive = element.getAsJsonPrimitive();
|
||||||
// However there is no easy way to clone a JsonPrimitive and I thought they were mutable anyways.
|
if (primitive.isBoolean()) return new JsonPrimitive(primitive.getAsBoolean());
|
||||||
return element;
|
if (primitive.isString()) return new JsonPrimitive(primitive.getAsString());
|
||||||
|
if (primitive.isNumber()) return new JsonPrimitive(primitive.getAsNumber());
|
||||||
|
|
||||||
|
throw new UnsupportedOperationException("The json primitive: " + primitive + " was not a boolean, number or string");
|
||||||
}
|
}
|
||||||
|
|
||||||
// JsonObject
|
// JsonObject
|
||||||
|
Loading…
Reference in New Issue
Block a user