All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.deque.axe.android.moshi.MoshiConfig.kt Maven / Gradle / Ivy

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