package com.mxn.helper.screenshot.server.controller

import com.mxn.helper.screenshot.helper.GsonHelper
import com.mxn.helper.screenshot.server.resp.BaseResp

abstract class BaseController {

    open fun convertToJson(any: Any): String {
        return try {
            GsonHelper.obtainGson().toJson(any)
        } catch (e: Throwable) {
            "error"
        }
    }

    open fun toJsonResponse(data: Any): String {
        return if (data is String) data.toString() else convertToJson(BaseResp(data))
    }

    open fun toJsonResponseOnlyOK(): String {
        return convertToJson(BaseResp())
    }


}