From d8fe269327a1a51f2588a3573a4764613da16388 Mon Sep 17 00:00:00 2001 From: Trumeet Date: Tue, 26 Jul 2022 19:06:11 -0700 Subject: Move the mod to mod/ --- src/main/java/moe/ymc/acron/c2s/ReqCmd.java | 51 ----------------------------- 1 file changed, 51 deletions(-) delete mode 100644 src/main/java/moe/ymc/acron/c2s/ReqCmd.java (limited to 'src/main/java/moe/ymc/acron/c2s/ReqCmd.java') diff --git a/src/main/java/moe/ymc/acron/c2s/ReqCmd.java b/src/main/java/moe/ymc/acron/c2s/ReqCmd.java deleted file mode 100644 index 6f34b07..0000000 --- a/src/main/java/moe/ymc/acron/c2s/ReqCmd.java +++ /dev/null @@ -1,51 +0,0 @@ -package moe.ymc.acron.c2s; - -import com.google.gson.*; -import com.google.gson.annotations.SerializedName; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.lang.reflect.Type; - -public record ReqCmd(@SerializedName("id") int id, - @SerializedName("cmd") @NotNull String cmd, - @SerializedName("config") @Nullable ReqSetConfig config) - implements Request { - @Override - public void validate() { - if (cmd == null) { - throw new IllegalArgumentException("Property 'cmd' cannot be null."); - } - } - - @Override - public int getId() { - return id; - } - - public static class ReqCmdDeserializer implements JsonDeserializer { - @Override - public ReqCmd deserialize(JsonElement json, - Type typeOfT, - JsonDeserializationContext context) throws JsonParseException { - final JsonObject object = json.getAsJsonObject(); - final int id = object.has("id") ? - object.get("id").getAsInt() : - -1; - final String cmd = object.has("cmd") ? - object.get("cmd").getAsString() : - null; - // We cannot use context#deserialize here - // because RuntimeTypeAdapterFactory keeps kicking in - // and asking for the 'type' property - // which is obviously redundant for an inner field. - // Thus, I pass it directly to the deserializer - // to bypass the RuntimeTypeAdapterFactory. - final ReqSetConfig reqSetConfig = object.has("config") ? - new ReqSetConfig.ReqSetConfigDeserializer() - .deserialize(object.get("config"), ReqSetConfig.class, context) : - null; - return new ReqCmd(id, cmd, reqSetConfig); - } - } -} -- cgit v1.2.3