Skip to content
This repository was archived by the owner on Jul 16, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ chucker-release = { module = "com.github.chuckerteam.chucker:library-no-op", ver
coil = { module = "io.coil-kt:coil", version.ref = "coil" }
coil-gif = { module = "io.coil-kt:coil-gif", version.ref = "coil" }
coil-svg = { module = "io.coil-kt:coil-svg", version.ref = "coil" }
fastjson = "com.alibaba:fastjson:1.1.72.android"
flycoTabLayout = "com.flyco.tablayout:FlycoTabLayout_Lib:2.2.0"
glide = { module = "com.github.bumptech.glide:glide", version.ref = "glide" }
glide-okhttp3 = { module = "com.github.bumptech.glide:okhttp3-integration", version.ref = "glide" }
Expand Down
1 change: 0 additions & 1 deletion obsolete/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ dependencies {
implementation(libs.square.okHttp)
implementation(libs.square.retrofit.gson)
implementation(libs.square.okHttp.logInterceptor)
implementation(libs.fastjson)
implementation(libs.google.gson)
implementation(libs.bundles.glide)
implementation(libs.rxJava3.java)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,77 +2,18 @@

package io.goooler.demoapp.obsolete.util

import com.alibaba.fastjson.JSONObject
import com.alibaba.fastjson.TypeReference
import com.google.gson.Gson
import java.lang.reflect.Type

sealed interface JsonConverter {
object GsonUtil {
@PublishedApi
internal val gson = Gson()

fun <T> fromJson(json: String, classOfT: Class<T>): T?
inline fun <reified T> fromJson(json: String, classOfT: Class<T>): T? =
runCatching { gson.fromJson(json, classOfT) }.getOrNull()

fun <T> fromJson(json: String, typeOfT: Type): T?
inline fun <reified T> fromJson(json: String, typeOfT: Type): T? =
runCatching { gson.fromJson<T>(json, typeOfT) }.getOrNull()

fun toJson(src: Any): String?
}

interface GsonUtil : JsonConverter {

companion object : GsonUtil {
private val gson = Gson()

override fun <T> fromJson(json: String, classOfT: Class<T>): T? = try {
gson.fromJson(json, classOfT)
} catch (e: Exception) {
e.printStackTrace()
null
}

override fun <T> fromJson(json: String, typeOfT: Type): T? = try {
gson.fromJson(json, typeOfT)
} catch (e: Exception) {
e.printStackTrace()
null
}

override fun toJson(src: Any): String? = try {
gson.toJson(src)
} catch (e: Exception) {
e.printStackTrace()
null
}
}
}

interface FastJsonUtil : JsonConverter {

fun <T> FastJsonUtil.Companion.fromJson(json: String, typeRef: TypeReference<T>): T? = try {
JSONObject.parseObject(json, typeRef)
} catch (e: Exception) {
e.printStackTrace()
null
}

companion object : FastJsonUtil {
override fun <T> fromJson(json: String, classOfT: Class<T>): T? = try {
JSONObject.parseObject(json, classOfT)
} catch (e: Exception) {
e.printStackTrace()
null
}

override fun <T> fromJson(json: String, typeOfT: Type): T? = try {
JSONObject.parseObject(json, typeOfT)
} catch (e: Exception) {
e.printStackTrace()
null
}

override fun toJson(src: Any): String? = try {
JSONObject.toJSONString(src)
} catch (e: Exception) {
e.printStackTrace()
null
}
}
fun toJson(src: Any): String? = runCatching { gson.toJson(src) }.getOrNull()
}