罗明文
18 小时以前 442124baa483f8d1c4aaca7ff81e15dd3f122363
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package com.dollearn.student.network
 
import cn.sinata.xldutils.sysErr
import com.google.gson.Gson
import com.google.gson.TypeAdapter
import okhttp3.ResponseBody
import retrofit2.Converter
import java.io.IOException
 
/**
 *
 */
class JsonResponseBodyConverter<T>(private val mGson: Gson, private val adapter: TypeAdapter<T>) : Converter<ResponseBody, T> {
 
    /**
     * 转换
     *
     * @param responseBody
     * @return
     * @throws IOException
     */
    @Throws(IOException::class)
    override fun convert(responseBody: ResponseBody): T {
        val s = responseBody.string()
        sysErr(s)
//        //如果返还值需解密
//        if (HttpManager.decodeDes) {
//            val type = object : TypeToken<ResultData<String>>() {
//
//            }.type
//            val data = mGson.fromJson<ResultData<String>>(s, type)
//            val newData = data.getDecodeDesString()
//            return adapter.fromJson(newData)
//        }
        //        JsonReader jsonReader = mGson.newJsonReader(responseBody.charStream());
        responseBody.use { _ ->
            return adapter.fromJson(s)
            //            return adapter.read(jsonReader);
        }
    }
}