package com.simplemobiletools.smsmessenger.helpers import androidx.room.TypeConverter import com.google.gson.Gson import com.google.gson.reflect.TypeToken import com.simplemobiletools.commons.models.SimpleContact import com.simplemobiletools.smsmessenger.models.Attachment import com.simplemobiletools.smsmessenger.models.MessageAttachment class Converters { private val gson = Gson() private val attachmentType = object : TypeToken>() {}.type private val simpleContactType = object : TypeToken>() {}.type private val messageAttachmentType = object : TypeToken() {}.type @TypeConverter fun jsonToAttachmentList(value: String) = gson.fromJson>(value, attachmentType) @TypeConverter fun attachmentListToJson(list: ArrayList) = gson.toJson(list) @TypeConverter fun jsonToSimpleContactList(value: String) = gson.fromJson>(value, simpleContactType) @TypeConverter fun simpleContactListToJson(list: ArrayList) = gson.toJson(list) @TypeConverter fun jsonToMessageAttachment(value: String) = gson.fromJson(value, messageAttachmentType) @TypeConverter fun messageAttachmentToJson(messageAttachment: MessageAttachment?) = gson.toJson(messageAttachment) }