Administrator
2021-11-09 5f50bd6ea5d5bdb7b8ea4d9e9a5851067b9aec1b
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package com.duqing.missions.retrofit.converter;
 
import com.google.gson.Gson;
import com.google.gson.TypeAdapter;
import com.google.gson.reflect.TypeToken;
 
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
 
import okhttp3.RequestBody;
import okhttp3.ResponseBody;
import retrofit2.Converter;
import retrofit2.Retrofit;
 
/**
 * My father is Object, ites purpose of     解密gson转换
 *
 * @purpose Created by Runt (qingingrunt2010@qq.com) on 2021-7-22.
 */
 
public class DecryptGsonConverterFactory extends Converter.Factory {
 
    public static DecryptGsonConverterFactory create() {
        return create(new Gson(),false);
    }
 
    public static DecryptGsonConverterFactory create(boolean transHump) {
        return create(new Gson(),transHump);
    }
 
 
    public static DecryptGsonConverterFactory create(Gson gson,boolean transHump) {
        return new DecryptGsonConverterFactory(gson,transHump);
    }
 
    private final Gson gson;
 
    private final boolean transHump;
 
    public DecryptGsonConverterFactory(Gson gson, boolean transHump) {
        if (gson == null) throw new NullPointerException("gson == null");
        this.gson = gson;
        this.transHump = transHump;
    }
 
    @Override
    public Converter<ResponseBody, ?> responseBodyConverter(Type type, Annotation[] annotations,
                                                            Retrofit retrofit) {
        TypeAdapter<?> adapter = gson.getAdapter(TypeToken.get(type));
        return new DecryptGsonResponseBodyConverter<>(gson, adapter,transHump);
    }
 
    @Override
    public Converter<?, RequestBody> requestBodyConverter(Type type,
                                                          Annotation[] parameterAnnotations, Annotation[] methodAnnotations, Retrofit retrofit) {
        TypeAdapter<?> adapter = gson.getAdapter(TypeToken.get(type));
        return new GsonRequestBodyConverter<>(gson, adapter);
    }
}