mirror of
https://github.com/rhunk/SnapEnhance.git
synced 2025-06-13 05:37:48 +02:00
fix(common): config deserializer error handler
This commit is contained in:
@ -2,6 +2,7 @@ package me.rhunk.snapenhance.common.config
|
|||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import com.google.gson.JsonObject
|
import com.google.gson.JsonObject
|
||||||
|
import me.rhunk.snapenhance.common.logger.AbstractLogger
|
||||||
import kotlin.reflect.KProperty
|
import kotlin.reflect.KProperty
|
||||||
|
|
||||||
typealias ConfigParamsBuilder = ConfigParams.() -> Unit
|
typealias ConfigParamsBuilder = ConfigParams.() -> Unit
|
||||||
@ -78,9 +79,12 @@ open class ConfigContainer(
|
|||||||
|
|
||||||
fun fromJson(json: JsonObject) {
|
fun fromJson(json: JsonObject) {
|
||||||
properties.forEach { (key, _) ->
|
properties.forEach { (key, _) ->
|
||||||
val jsonElement = json.get(key.name) ?: return@forEach
|
runCatching {
|
||||||
//TODO: check incoming values
|
val jsonElement = json.get(key.name) ?: return@forEach
|
||||||
properties[key]?.setAny(key.dataType.deserializeAny(jsonElement))
|
properties[key]?.setAny(key.dataType.deserializeAny(jsonElement))
|
||||||
|
}.onFailure {
|
||||||
|
AbstractLogger.directError("Failed to deserialize property ${key.name}", it)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user