/app/src/main/java/com/gzsll/hupu/components/retrofit/FastJsonResponseBodyConverter.java
Java | 33 lines | 24 code | 6 blank | 3 comment | 0 complexity | 45a83c59383f93adea281cdb0214e5dc MD5 | raw file
- package com.gzsll.hupu.components.retrofit;
- import com.alibaba.fastjson.JSON;
- import java.io.IOException;
- import java.lang.reflect.Type;
- import java.nio.charset.Charset;
- import okhttp3.ResponseBody;
- import retrofit2.Converter;
- /**
- * Created by sll on 2016/3/31.
- */
- public class FastJsonResponseBodyConverter<T> implements Converter<ResponseBody, T> {
- private Type type;
- private Charset charset;
- public FastJsonResponseBodyConverter() {
- }
- public FastJsonResponseBodyConverter(Type type, Charset charset) {
- this.type = type;
- this.charset = charset;
- }
- @Override public T convert(ResponseBody value) throws IOException {
- try {
- return JSON.parseObject(value.string(), type);
- } finally {
- value.close();
- }
- }
- }