diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/utils/FeatureTogglesByDefaultAdapter.kt | 16 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/utils/ReflectionUtils.kt | 1 |
2 files changed, 14 insertions, 3 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/FeatureTogglesByDefaultAdapter.kt b/src/main/java/at/hannibal2/skyhanni/utils/FeatureTogglesByDefaultAdapter.kt index 011dcc10c..f78a0c4dc 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/FeatureTogglesByDefaultAdapter.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/FeatureTogglesByDefaultAdapter.kt @@ -1,6 +1,7 @@ package at.hannibal2.skyhanni.utils import at.hannibal2.skyhanni.config.FeatureToggle +import at.hannibal2.skyhanni.utils.ReflectionUtils.getDeclaredFieldOrNull import com.google.gson.Gson import com.google.gson.JsonObject import com.google.gson.JsonPrimitive @@ -49,8 +50,17 @@ object FeatureTogglesByDefaultAdapter : TypeAdapterFactory { // Read the actual JSON Object while (reader.peek() != JsonToken.END_OBJECT) { + // IllegalStateException: Expected NAME but was BOOLEAN + if (reader.peek() != JsonToken.NAME) { + reader.skipValue() + continue + } val name = reader.nextName() - val field = clazz.getDeclaredField(name) + val field = clazz.getDeclaredFieldOrNull(name) + if (field == null) { + println("field is in config file, but not in object file: $name") + continue + } val fieldType = gson.getAdapter(TypeToken.get(getType(type, field))) // Read the field data val data = fieldType.read(reader) @@ -70,10 +80,10 @@ object FeatureTogglesByDefaultAdapter : TypeAdapterFactory { // Check if this object has any feature toggles present if (t.fields.none { it.isAnnotationPresent(FeatureToggle::class.java) || - gson.getAdapter(TypeToken.get(getType(type, it))) is Adapter + gson.getAdapter(TypeToken.get(getType(type, it))) is Adapter }) return null val originalWrite = gson.getDelegateAdapter(this, type) return Adapter(originalWrite, t as Class<T>, gson, type) } -}
\ No newline at end of file +} diff --git a/src/main/java/at/hannibal2/skyhanni/utils/ReflectionUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/ReflectionUtils.kt index d8ebbaf68..1fe8b882c 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/ReflectionUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/ReflectionUtils.kt @@ -80,4 +80,5 @@ object ReflectionUtils { return packageLookup[shPackageName] } + fun Class<*>.getDeclaredFieldOrNull(name: String): Field? = declaredFields.firstOrNull { it.name == name } } |