diff --git a/WORKSPACE b/WORKSPACE index e518b022..bbb681dc 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -185,10 +185,6 @@ maven_install( "androidx.room:room-runtime:2.2.6", "androidx.room:room-testing:2.2.6", "androidx.test.ext:junit:1.1.2", - "com.fasterxml.jackson.core:jackson-annotations:2.13.4", - "com.fasterxml.jackson.core:jackson-core:2.13.4", - "com.fasterxml.jackson.core:jackson-databind:2.13.4", - "com.fasterxml.jackson.module:jackson-module-kotlin:2.13.4", "com.google.android.material:material:1.4.0", "com.google.code.gson:gson:2.8.6", "com.google.guava:guava:19.0", diff --git a/domain/BUILD.bazel b/domain/BUILD.bazel index 3e0ddbbf..fc88bc60 100644 --- a/domain/BUILD.bazel +++ b/domain/BUILD.bazel @@ -30,10 +30,6 @@ kt_android_library( ":tox4j", "//core", "@maven//:androidx_core_core_ktx", - "@maven//:com_fasterxml_jackson_core_jackson_annotations", - "@maven//:com_fasterxml_jackson_core_jackson_core", - "@maven//:com_fasterxml_jackson_core_jackson_databind", - "@maven//:com_fasterxml_jackson_module_jackson_module_kotlin", ], ) diff --git a/domain/build.gradle.kts b/domain/build.gradle.kts index eb93447a..0099e86d 100644 --- a/domain/build.gradle.kts +++ b/domain/build.gradle.kts @@ -66,12 +66,6 @@ dependencies { api(libs.tox4j.api) implementation(libs.tox4j.c) - // JSON - implementation(libs.jackson.kotlin) - implementation(libs.jackson.databind) - implementation(libs.jackson.core) - implementation(libs.jackson.annotations) - testImplementation(kotlin("test")) androidTestImplementation(kotlin("test")) androidTestImplementation(libs.test.runner) diff --git a/domain/src/main/kotlin/feature/ExportManager.kt b/domain/src/main/kotlin/feature/ExportManager.kt index 06b6352b..745d7e20 100644 --- a/domain/src/main/kotlin/feature/ExportManager.kt +++ b/domain/src/main/kotlin/feature/ExportManager.kt @@ -1,10 +1,10 @@ // SPDX-FileCopyrightText: 2022 Akito +// SPDX-FileCopyrightText: 2023 Robin Lindén // // SPDX-License-Identifier: GPL-3.0-only package ltd.evilcorp.domain.feature -import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper import java.text.SimpleDateFormat import java.util.Date import java.util.Locale @@ -13,24 +13,36 @@ import kotlinx.coroutines.flow.first import kotlinx.coroutines.runBlocking import ltd.evilcorp.core.repository.MessageRepository import ltd.evilcorp.core.vo.Message +import org.json.JSONArray +import org.json.JSONObject class ExportManager @Inject constructor( private val messageRepository: MessageRepository, ) { - // TODO @Akito: Increment version programmatically on major changes. - private fun List.generateExportMessages(): ExportMessages { - return ExportMessages( - version = 1, - timestamp = SimpleDateFormat( - """yyyy-MM-dd'T'HH-mm-ss""", - Locale.getDefault(), - ).format(Date()), - entries = this, + private fun generateExportMessagesJString(messages: List): String { + val root = JSONObject() + root.put("version", 1) + root.put( + "timestamp", + SimpleDateFormat("""yyyy-MM-dd'T'HH-mm-ss""", Locale.getDefault()).format(Date()), ) - } - private fun generateExportMessagesJString(messages: List): String = - jacksonObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(messages.generateExportMessages()) + val entries = JSONArray() + for (message in messages) { + val jsonMessage = JSONObject().apply { + put("publicKey", message.publicKey) + put("message", message.message) + put("sender", message.sender.toString()) + put("type", message.type.toString()) + put("correlationId", message.correlationId) + put("timestamp", message.timestamp) + put("id", message.id) + } + entries.put(jsonMessage) + } + root.put("entries", entries) + return root.toString(2) + } private fun getMessages(publicKey: String): List = runBlocking { messageRepository.get(publicKey).first() @@ -40,9 +52,3 @@ class ExportManager @Inject constructor( getMessages(publicKey), ) } - -data class ExportMessages( - val version: Int, - val timestamp: String, - val entries: List, -) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 4591595c..0bb2fd67 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -9,7 +9,6 @@ android-plugin = "8.1.2" coroutines = "1.7.3" dagger = "2.48" espresso = "3.5.1" -jackson = "2.15.2" lifecycle = "2.6.2" navigation = "2.6.0" # 2.7.5 requires API 34. room = "2.5.2" # 2.6.0 requires API 34. @@ -48,11 +47,6 @@ google-android-material = "com.google.android.material:material:1.9.0" # 1.10.0 google-dagger-compiler = { module = "com.google.dagger:dagger-compiler", version.ref = "dagger" } google-dagger-core = { module = "com.google.dagger:dagger", version.ref = "dagger" } -jackson-kotlin = { module = "com.fasterxml.jackson.module:jackson-module-kotlin", version.ref = "jackson" } -jackson-databind = { module = "com.fasterxml.jackson.core:jackson-databind", version.ref = "jackson" } -jackson-core = { module = "com.fasterxml.jackson.core:jackson-core", version.ref = "jackson" } -jackson-annotations = { module = "com.fasterxml.jackson.core:jackson-annotations", version.ref = "jackson" } - javax-inject = "javax.inject:javax.inject:1" kotlinx-coroutines-android = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-android", version.ref = "coroutines" }