diff --git a/src/main/java/xyz/xenondevs/nova/serialization/gson/EnumMapInstanceCreator.java b/src/main/java/xyz/xenondevs/nova/serialization/gson/EnumMapInstanceCreator.java deleted file mode 100644 index ba17d40a9e2..00000000000 --- a/src/main/java/xyz/xenondevs/nova/serialization/gson/EnumMapInstanceCreator.java +++ /dev/null @@ -1,18 +0,0 @@ -package xyz.xenondevs.nova.serialization.gson; - -import com.google.gson.InstanceCreator; - -import java.lang.reflect.ParameterizedType; -import java.lang.reflect.Type; -import java.util.EnumMap; - -// doesn't seem to work in kotlin -@SuppressWarnings({"unchecked", "rawtypes"}) -public class EnumMapInstanceCreator implements InstanceCreator> { - - // https://stackoverflow.com/questions/54966118/how-to-deserialize-an-enummap - public EnumMap createInstance(Type type) { - return new EnumMap((Class) ((ParameterizedType) type).getActualTypeArguments()[0]); - } - -} diff --git a/src/main/kotlin/xyz/xenondevs/nova/serialization/gson/EnumMapInstanceCreator.kt b/src/main/kotlin/xyz/xenondevs/nova/serialization/gson/EnumMapInstanceCreator.kt new file mode 100644 index 00000000000..969727264ab --- /dev/null +++ b/src/main/kotlin/xyz/xenondevs/nova/serialization/gson/EnumMapInstanceCreator.kt @@ -0,0 +1,17 @@ +package xyz.xenondevs.nova.serialization.gson + +import com.google.gson.InstanceCreator +import java.lang.reflect.ParameterizedType +import java.lang.reflect.Type +import java.util.* + +private val ENUMMAP_CONSTRUCTOR = EnumMap::class.java.getConstructor(Class::class.java) + +class EnumMapInstanceCreator : InstanceCreator> { + + // https://stackoverflow.com/questions/54966118/how-to-deserialize-an-enummap + override fun createInstance(type: Type): EnumMap<*, *> { + return ENUMMAP_CONSTRUCTOR.newInstance((type as ParameterizedType).actualTypeArguments[0] as Class<*>) + } + +} \ No newline at end of file