/app/src/main/java/com/gzsll/hupu/components/retrofit/FastJsonRequestBodyConverter.java
Java | 28 lines | 20 code | 5 blank | 3 comment | 0 complexity | 972fc163ea9e2d3f27d0715ed6f26b8f 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.MediaType;
- import okhttp3.RequestBody;
- import retrofit2.Converter;
- /**
- * Created by sll on 2016/3/31.
- */
- public class FastJsonRequestBodyConverter<T> implements Converter<T, RequestBody> {
- private Type type;
- private Charset charset;
- private static final MediaType MEDIA_TYPE = MediaType.parse("application/json; charset=UTF-8");
- public FastJsonRequestBodyConverter(Type type, Charset charset) {
- this.type = type;
- this.charset = charset;
- }
- @Override public RequestBody convert(T value) throws IOException {
- return RequestBody.create(MEDIA_TYPE, JSON.toJSONString(value).getBytes(charset));
- }
- }