Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2019
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.45 KB | None | 0 0
  1. package fr.opperdev.apispigot.tools;
  2.  
  3. import com.google.gson.*;
  4.  
  5. import java.lang.reflect.Type;
  6. import java.util.UUID;
  7.  
  8. /**
  9.  * Created by user on 22/03/2019.
  10.  */
  11. public class UserDeserializer implements JsonDeserializer<User> {
  12.     @Override
  13.     public User deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jdc) throws JsonParseException {
  14.         JsonObject object = (JsonObject) jsonElement;
  15.         UUID id = object.has("id") ? (UUID) jdc.deserialize(object.get("id"), UUID.class) : null;
  16.         String name = object.has("name") ? object.getAsJsonPrimitive("name").getAsString() : null;
  17.         long coins = object.has("coins") ? object.getAsJsonPrimitive("coins").getAsLong() : null;
  18.         long kcoins = object.has("kcoins") ? object.getAsJsonPrimitive("kcoins").getAsLong() : null;
  19.         Ranks rank = object.has("rank") ? (Ranks) jdc.deserialize(object.get("rank"), Ranks.class) : null;
  20.         long muted = object.has("muted") ? object.getAsJsonPrimitive("muted").getAsLong() : null;
  21.         long banned = object.has("banned") ? object.getAsJsonPrimitive("banned").getAsLong() : null;
  22.         String banReason = object.has("banReason") ? object.getAsJsonPrimitive("banReason").getAsString() : null;
  23.         String muteReason = object.has("muteReason") ? object.getAsJsonPrimitive("muteReason").getAsString() : null;
  24.         return new User(id, name, coins, kcoins, rank, muted, banned, banReason, muteReason);
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement