Convert SY specific usages of Gson to Kotlin Serialization

Cleanup saved searches a bit
Cleanup json parsing
This commit is contained in:
Jobobby04
2020-10-12 14:20:54 -04:00
parent bbfce97125
commit f3365cef67
46 changed files with 490 additions and 366 deletions
@@ -1,20 +1,19 @@
package exh.log
import com.elvishew.xlog.XLog
import com.google.gson.Gson
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.json.Json
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
fun OkHttpClient.Builder.maybeInjectEHLogger(): OkHttpClient.Builder {
if (EHLogLevel.shouldLog(EHLogLevel.EXTREME)) {
val logger: HttpLoggingInterceptor.Logger = object : HttpLoggingInterceptor.Logger {
override fun log(message: String) {
try {
Gson().fromJson(message, Any::class.java)
XLog.tag("||EH-NETWORK-JSON").nst().json(message)
} catch (ex: Exception) {
XLog.tag("||EH-NETWORK").nb().nst().d(message)
}
val logger: HttpLoggingInterceptor.Logger = HttpLoggingInterceptor.Logger { message ->
try {
Json.decodeFromString<Any>(message)
XLog.tag("||EH-NETWORK-JSON").nst().json(message)
} catch (ex: Exception) {
XLog.tag("||EH-NETWORK").nb().nst().d(message)
}
}
return addInterceptor(HttpLoggingInterceptor(logger).apply { level = HttpLoggingInterceptor.Level.BODY })