Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package fr.opperdev.apispigot.tools;
- import com.google.gson.*;
- import java.lang.reflect.Type;
- import java.util.UUID;
- /**
- * Created by user on 22/03/2019.
- */
- public class UserDeserializer implements JsonDeserializer<User> {
- @Override
- public User deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jdc) throws JsonParseException {
- JsonObject object = (JsonObject) jsonElement;
- UUID id = object.has("id") ? (UUID) jdc.deserialize(object.get("id"), UUID.class) : null;
- String name = object.has("name") ? object.getAsJsonPrimitive("name").getAsString() : null;
- long coins = object.has("coins") ? object.getAsJsonPrimitive("coins").getAsLong() : null;
- long kcoins = object.has("kcoins") ? object.getAsJsonPrimitive("kcoins").getAsLong() : null;
- Ranks rank = object.has("rank") ? (Ranks) jdc.deserialize(object.get("rank"), Ranks.class) : null;
- long muted = object.has("muted") ? object.getAsJsonPrimitive("muted").getAsLong() : null;
- long banned = object.has("banned") ? object.getAsJsonPrimitive("banned").getAsLong() : null;
- String banReason = object.has("banReason") ? object.getAsJsonPrimitive("banReason").getAsString() : null;
- String muteReason = object.has("muteReason") ? object.getAsJsonPrimitive("muteReason").getAsString() : null;
- return new User(id, name, coins, kcoins, rank, muted, banned, banReason, muteReason);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement