package tech.summerly.quiet.extensions

import android.net.Uri
import com.google.gson.*
import java.lang.reflect.Type

/**
 * author : summerly
 * e-mail : yangbinyhbn@gmail.com
 * time   : 2017/7/22
 * desc   :
 */
val uriTypeAdapter: Any = object : JsonSerializer<Uri>, JsonDeserializer<Uri> {

    override fun serialize(src: Uri?, typeOfSrc: Type?, context: JsonSerializationContext?): JsonElement {
        return JsonPrimitive(src?.toString())
    }

    override fun deserialize(json: JsonElement, typeOfT: Type?, context: JsonDeserializationContext?): Uri {
        return Uri.parse(json.asString)
    }

}