mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-11-16 03:59:14 +03:00
30 lines
1.1 KiB
Java
30 lines
1.1 KiB
Java
|
package ru.gravit.launchserver.config;
|
||
|
|
||
|
import com.google.gson.*;
|
||
|
import ru.gravit.launchserver.auth.handler.AuthHandler;
|
||
|
import ru.gravit.launchserver.auth.hwid.HWIDHandler;
|
||
|
|
||
|
import java.lang.reflect.Type;
|
||
|
|
||
|
public class HWIDHandlerAdapter implements JsonSerializer<HWIDHandler>, JsonDeserializer<HWIDHandler> {
|
||
|
private static final String PROP_NAME = "type";
|
||
|
@Override
|
||
|
public HWIDHandler deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
||
|
String typename = json.getAsJsonObject().getAsJsonPrimitive(PROP_NAME).getAsString();
|
||
|
Class<HWIDHandler> cls = HWIDHandler.getHandlerClass(typename);
|
||
|
|
||
|
|
||
|
return (HWIDHandler) context.deserialize(json, cls);
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public JsonElement serialize(HWIDHandler src, Type typeOfSrc, JsonSerializationContext context) {
|
||
|
JsonObject jo = context.serialize(src).getAsJsonObject();
|
||
|
|
||
|
String classPath = HWIDHandler.getHandlerName(src.getClass());
|
||
|
jo.add(PROP_NAME, new JsonPrimitive(classPath));
|
||
|
|
||
|
return jo;
|
||
|
}
|
||
|
}
|