diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupManager.kt b/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupManager.kt index b775f595b..367614487 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupManager.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupManager.kt @@ -3,8 +3,10 @@ package eu.kanade.tachiyomi.data.backup import com.github.salomonbrys.kotson.fromJson import com.google.gson.* import com.google.gson.stream.JsonReader +import eu.kanade.tachiyomi.data.backup.serializer.BooleanSerializer import eu.kanade.tachiyomi.data.backup.serializer.IdExclusion import eu.kanade.tachiyomi.data.backup.serializer.IntegerSerializer +import eu.kanade.tachiyomi.data.backup.serializer.LongSerializer import eu.kanade.tachiyomi.data.database.DatabaseHelper import eu.kanade.tachiyomi.data.database.models.* import java.io.* @@ -42,7 +44,9 @@ class BackupManager(private val db: DatabaseHelper) { @Suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN") private val gson = GsonBuilder() - .registerTypeAdapter(Integer::class.java, IntegerSerializer()) + .registerTypeAdapter(java.lang.Integer::class.java, IntegerSerializer()) + .registerTypeAdapter(java.lang.Boolean::class.java, BooleanSerializer()) + .registerTypeAdapter(java.lang.Long::class.java, LongSerializer()) .setExclusionStrategies(IdExclusion()) .create() diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/backup/serializer/BooleanSerializer.kt b/app/src/main/java/eu/kanade/tachiyomi/data/backup/serializer/BooleanSerializer.kt new file mode 100644 index 000000000..14d5a4236 --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/data/backup/serializer/BooleanSerializer.kt @@ -0,0 +1,16 @@ +package eu.kanade.tachiyomi.data.backup.serializer + +import com.google.gson.JsonElement +import com.google.gson.JsonPrimitive +import com.google.gson.JsonSerializationContext +import com.google.gson.JsonSerializer +import java.lang.reflect.Type + +class BooleanSerializer : JsonSerializer { + + override fun serialize(value: Boolean?, type: Type, context: JsonSerializationContext): JsonElement? { + if (value != null && value != false) + return JsonPrimitive(value) + return null + } +} diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/backup/serializer/IdExclusion.kt b/app/src/main/java/eu/kanade/tachiyomi/data/backup/serializer/IdExclusion.kt index 867cb81b3..92c95cb03 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/backup/serializer/IdExclusion.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/backup/serializer/IdExclusion.kt @@ -2,10 +2,10 @@ package eu.kanade.tachiyomi.data.backup.serializer import com.google.gson.ExclusionStrategy import com.google.gson.FieldAttributes -import eu.kanade.tachiyomi.data.database.models.Category -import eu.kanade.tachiyomi.data.database.models.Chapter -import eu.kanade.tachiyomi.data.database.models.Manga -import eu.kanade.tachiyomi.data.database.models.MangaSync +import eu.kanade.tachiyomi.data.database.models.CategoryImpl +import eu.kanade.tachiyomi.data.database.models.ChapterImpl +import eu.kanade.tachiyomi.data.database.models.MangaImpl +import eu.kanade.tachiyomi.data.database.models.MangaSyncImpl class IdExclusion : ExclusionStrategy { @@ -15,10 +15,10 @@ class IdExclusion : ExclusionStrategy { private val syncExclusions = listOf("id", "manga_id", "update") override fun shouldSkipField(f: FieldAttributes) = when (f.declaringClass) { - Manga::class.java -> mangaExclusions.contains(f.name) - Chapter::class.java -> chapterExclusions.contains(f.name) - MangaSync::class.java -> syncExclusions.contains(f.name) - Category::class.java -> categoryExclusions.contains(f.name) + MangaImpl::class.java -> mangaExclusions.contains(f.name) + ChapterImpl::class.java -> chapterExclusions.contains(f.name) + MangaSyncImpl::class.java -> syncExclusions.contains(f.name) + CategoryImpl::class.java -> categoryExclusions.contains(f.name) else -> false } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/backup/serializer/LongSerializer.kt b/app/src/main/java/eu/kanade/tachiyomi/data/backup/serializer/LongSerializer.kt new file mode 100644 index 000000000..be62e3fe1 --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/data/backup/serializer/LongSerializer.kt @@ -0,0 +1,16 @@ +package eu.kanade.tachiyomi.data.backup.serializer + +import com.google.gson.JsonElement +import com.google.gson.JsonPrimitive +import com.google.gson.JsonSerializationContext +import com.google.gson.JsonSerializer +import java.lang.reflect.Type + +class LongSerializer : JsonSerializer { + + override fun serialize(value: Long?, type: Type, context: JsonSerializationContext): JsonElement? { + if (value != null && value !== 0L) + return JsonPrimitive(value) + return null + } +}