com.deque.axe.android.moshi.MoshiConfig.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of axe-devtools-android-core Show documentation
Show all versions of axe-devtools-android-core Show documentation
The Axe Devtools Android Core Library
The newest version!
package com.deque.axe.android.moshi
import com.deque.axe.android.utils.SuppressFBWarnings
import com.squareup.moshi.Moshi
import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory
object MoshiConfig {
private val extraAdapters = mutableSetOf()
val axeMoshiConfig get() = AxeMoshiConfig(extraAdapters)
fun prettyPrint(uglyPrint: T, clazz: Class): String {
return AxeMoshiConfig(extraAdapters).moshi.adapter(clazz).indent(" ").toJson(uglyPrint)
}
@SuppressFBWarnings
fun addAdapters(adapterSet: Set) {
extraAdapters.addAll(adapterSet)
}
}
class AxeMoshiConfig(additionalAdapters: Set = setOf()) {
val moshi: Moshi get() = _moshi
private var _moshi = getMoshiInstance(additionalAdapters)
private fun getMoshiInstance(additionalAdapters: Set): Moshi {
val builder = Moshi.Builder()
additionalAdapters.forEach { builder.add(it) }
builder
.add(AxeEventStreamAdapter())
.add(AxeColorAdapter())
.add(AxeViewAdapter())
.add(AxeResultAdapter())
.add(AxePropsAdapter())
.add(AccessTokenResponseAdapter())
.addLast(KotlinJsonAdapterFactory())
return builder.build()
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy