diff --git a/src/commonMain/kotlin/app/revanced/library/Serialization.kt b/src/commonMain/kotlin/app/revanced/library/Serialization.kt index 1b1641a..fea9d74 100644 --- a/src/commonMain/kotlin/app/revanced/library/Serialization.kt +++ b/src/commonMain/kotlin/app/revanced/library/Serialization.kt @@ -1,14 +1,19 @@ package app.revanced.library -import app.revanced.patcher.patch.* -import kotlinx.serialization.* +import app.revanced.patcher.patch.Option +import app.revanced.patcher.patch.Patch +import app.revanced.patcher.patch.VersionName +import kotlinx.serialization.ExperimentalSerializationApi +import kotlinx.serialization.KSerializer import kotlinx.serialization.builtins.* import kotlinx.serialization.descriptors.buildClassSerialDescriptor import kotlinx.serialization.descriptors.element import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder import kotlinx.serialization.encoding.encodeStructure -import kotlinx.serialization.json.* +import kotlinx.serialization.json.Json +import kotlinx.serialization.json.encodeToStream +import kotlinx.serialization.serializer import java.io.OutputStream private class PatchSerializer : KSerializer> { @@ -17,7 +22,7 @@ private class PatchSerializer : KSerializer> { element("description") element("use") element>("dependencies") - element?>("compatiblePackages") + element?>?>("compatiblePackages") element("options", OptionSerializer.descriptor) } @@ -52,8 +57,8 @@ private class PatchSerializer : KSerializer> { encodeNullableSerializableElement( descriptor, 4, - SetSerializer(PairSerializer(String.serializer(), SetSerializer(String.serializer()).nullable)), - value.compatiblePackages, + MapSerializer(String.serializer(), SetSerializer(String.serializer()).nullable), + value.compatiblePackages?.associate { (packageName, versions) -> packageName to versions }, ) encodeSerializableElement( descriptor, diff --git a/src/commonTest/kotlin/app/revanced/library/SerializationTest.kt b/src/commonTest/kotlin/app/revanced/library/SerializationTest.kt index 7a8727e..b457f30 100644 --- a/src/commonTest/kotlin/app/revanced/library/SerializationTest.kt +++ b/src/commonTest/kotlin/app/revanced/library/SerializationTest.kt @@ -1,6 +1,9 @@ package app.revanced.library -import app.revanced.patcher.patch.* +import app.revanced.patcher.patch.booleanOption +import app.revanced.patcher.patch.bytecodePatch +import app.revanced.patcher.patch.floatsOption +import app.revanced.patcher.patch.stringOption import kotlinx.serialization.json.* import java.io.ByteArrayOutputStream import kotlin.test.Test @@ -33,7 +36,7 @@ class SerializationTest { assert(deserializedPatch["name"]!!.jsonPrimitive.content == "Test patch") - assert(deserializedPatch["compatiblePackages"]!!.jsonArray.size == 2) { + assert(deserializedPatch["compatiblePackages"]!!.jsonObject.size == 2) { "The patch should be compatible with two packages." }