package com.diegocayo.organizame.utils.moshi

import com.squareup.moshi.JsonAdapter
import com.squareup.moshi.Moshi

class MoshiParser(private val moshi: Moshi) {

    fun <T> toJson(data: T, type: Class<T>): String {
        val adapter: JsonAdapter<T> = moshi.adapter(type)
        return adapter.toJson(data)
    }

    fun <T> fromJson(json: String, type: Class<T>): T? {
        val adapter: JsonAdapter<T> = moshi.adapter(type)
        return adapter.fromJson(json)
    }
}