PageRenderTime 36ms CodeModel.GetById 10ms RepoModel.GetById 1ms app.codeStats 0ms

/app/src/main/java/com/gzsll/hupu/components/retrofit/FastJsonResponseBodyConverter.java

https://gitlab.com/gzsll/TLint
Java | 33 lines | 24 code | 6 blank | 3 comment | 0 complexity | 45a83c59383f93adea281cdb0214e5dc MD5 | raw file
  1. package com.gzsll.hupu.components.retrofit;
  2. import com.alibaba.fastjson.JSON;
  3. import java.io.IOException;
  4. import java.lang.reflect.Type;
  5. import java.nio.charset.Charset;
  6. import okhttp3.ResponseBody;
  7. import retrofit2.Converter;
  8. /**
  9. * Created by sll on 2016/3/31.
  10. */
  11. public class FastJsonResponseBodyConverter<T> implements Converter<ResponseBody, T> {
  12. private Type type;
  13. private Charset charset;
  14. public FastJsonResponseBodyConverter() {
  15. }
  16. public FastJsonResponseBodyConverter(Type type, Charset charset) {
  17. this.type = type;
  18. this.charset = charset;
  19. }
  20. @Override public T convert(ResponseBody value) throws IOException {
  21. try {
  22. return JSON.parseObject(value.string(), type);
  23. } finally {
  24. value.close();
  25. }
  26. }
  27. }