17 lines
541 B
Kotlin
17 lines
541 B
Kotlin
package com.danilafe.fencelessgrazing.requests
|
|
|
|
import android.util.Log
|
|
import com.android.volley.Response
|
|
import com.google.gson.Gson
|
|
import java.lang.reflect.Type
|
|
|
|
class GsonListener<T : Any>(private val targetType : Type, private val stringListener : Response.Listener<T>) : Response.Listener<String> {
|
|
|
|
private val gson = Gson()
|
|
|
|
override fun onResponse(response: String?) {
|
|
if(response == null) { return stringListener.onResponse(null) }
|
|
stringListener.onResponse(gson.fromJson<T>(response, targetType))
|
|
}
|
|
|
|
} |