package com.rc.httpcore.interceptor.formatter

import com.google.gson.GsonBuilder
import com.google.gson.JsonParser

class GsonFormatter : JSONFormatter() {

    companion object {
        fun buildIfSupported(): JSONFormatter? {
            return try {
                Class.forName("com.google.gson.Gson")
                GsonFormatter()
            } catch (ignore: ClassNotFoundException) {
                null
            }
        }
    }

    private val GSON = GsonBuilder().setPrettyPrinting().create()
    private val PARSER = JsonParser()

    override fun format(source: String?): String? {
        return GSON.toJson(PARSER.parse(source))
    }

}