refactor!: support resource obfuscation
There are still many bugs but it is stable enough for daily usage
This commit is contained in:
@@ -83,7 +83,8 @@ abstract class AbstractClassMapper(
|
||||
}
|
||||
}
|
||||
|
||||
fun writeFromJson(json: JsonObject) {
|
||||
fun writeFromJson(json: JsonObject): List<String> {
|
||||
val warns = mutableListOf<String>()
|
||||
values.forEach { (key, value) ->
|
||||
runCatching {
|
||||
when (value) {
|
||||
@@ -95,7 +96,11 @@ abstract class AbstractClassMapper(
|
||||
}.onFailure {
|
||||
Log.e("Mapper","Failed to serialize property $key")
|
||||
}
|
||||
if (json.get(key).let { it.isJsonNull || (it.isJsonPrimitive && it.asString == "null") }) {
|
||||
warns.add("Failed to serialize property $key in $mapperName")
|
||||
}
|
||||
}
|
||||
return warns
|
||||
}
|
||||
|
||||
fun mapper(task: MapperContext.() -> Unit) {
|
||||
|
||||
@@ -17,6 +17,7 @@ class ClassMapper(
|
||||
private vararg val mappers: AbstractClassMapper = DEFAULT_MAPPERS,
|
||||
) {
|
||||
private val classes = mutableListOf<ClassDef>()
|
||||
private val warnings = mutableListOf<String>()
|
||||
|
||||
companion object {
|
||||
val DEFAULT_MAPPERS get() = arrayOf(
|
||||
@@ -73,6 +74,8 @@ class ClassMapper(
|
||||
}
|
||||
}
|
||||
|
||||
fun getWarns() = warnings
|
||||
|
||||
suspend fun run(): JsonObject {
|
||||
val context = MapperContext(classes.associateBy { it.type })
|
||||
|
||||
@@ -87,7 +90,7 @@ class ClassMapper(
|
||||
val outputJson = JsonObject()
|
||||
mappers.forEach { mapper ->
|
||||
outputJson.add(mapper.mapperName, JsonObject().apply {
|
||||
mapper.writeFromJson(this)
|
||||
warnings.addAll(mapper.writeFromJson(this))
|
||||
})
|
||||
}
|
||||
return outputJson
|
||||
|
||||
Reference in New Issue
Block a user