package com.rc.httpcore.interceptor.formatter

import org.json.JSONException

/**
 * json格式化
 */
open class JSONFormatter {

    companion object {

        private val FORMATTER = findJSONFormatter()

        fun formatJSON(source: String?): String? {
            return try {
                FORMATTER.format(source)
            } catch (e: java.lang.Exception) {
                ""
            }
        }

        private fun findJSONFormatter(): JSONFormatter {
            val jsonFormatter = OrgJsonFormatter.buildIfSupported()
            if (jsonFormatter != null) {
                return jsonFormatter
            }
            val gsonFormatter = GsonFormatter.buildIfSupported()
            return gsonFormatter ?: JSONFormatter()
        }
    }

    @Throws(JSONException::class)
    open fun format(source: String?): String? {
        return ""
    }

}