Initial commit
This commit is contained in:
40
sources/retrofit2/converter/gson/GsonConverterFactory.java
Normal file
40
sources/retrofit2/converter/gson/GsonConverterFactory.java
Normal file
@@ -0,0 +1,40 @@
|
||||
package retrofit2.converter.gson;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
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;
|
||||
|
||||
/* loaded from: classes2.dex */
|
||||
public final class GsonConverterFactory extends Converter.Factory {
|
||||
private final Gson gson;
|
||||
|
||||
private GsonConverterFactory(Gson gson) {
|
||||
this.gson = gson;
|
||||
}
|
||||
|
||||
public static GsonConverterFactory create() {
|
||||
return create(new Gson());
|
||||
}
|
||||
|
||||
@Override // retrofit2.Converter.Factory
|
||||
public Converter<?, RequestBody> requestBodyConverter(Type type, Annotation[] annotationArr, Annotation[] annotationArr2, Retrofit retrofit) {
|
||||
return new GsonRequestBodyConverter(this.gson, this.gson.getAdapter(TypeToken.get(type)));
|
||||
}
|
||||
|
||||
@Override // retrofit2.Converter.Factory
|
||||
public Converter<ResponseBody, ?> responseBodyConverter(Type type, Annotation[] annotationArr, Retrofit retrofit) {
|
||||
return new GsonResponseBodyConverter(this.gson, this.gson.getAdapter(TypeToken.get(type)));
|
||||
}
|
||||
|
||||
public static GsonConverterFactory create(Gson gson) {
|
||||
if (gson != null) {
|
||||
return new GsonConverterFactory(gson);
|
||||
}
|
||||
throw new NullPointerException("gson == null");
|
||||
}
|
||||
}
|
@@ -0,0 +1,40 @@
|
||||
package retrofit2.converter.gson;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.TypeAdapter;
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.nio.charset.Charset;
|
||||
import okhttp3.MediaType;
|
||||
import okhttp3.RequestBody;
|
||||
import okio.Buffer;
|
||||
import retrofit2.Converter;
|
||||
|
||||
/* loaded from: classes2.dex */
|
||||
final class GsonRequestBodyConverter<T> implements Converter<T, RequestBody> {
|
||||
private static final MediaType MEDIA_TYPE = MediaType.parse("application/json; charset=UTF-8");
|
||||
private static final Charset UTF_8 = Charset.forName("UTF-8");
|
||||
private final TypeAdapter<T> adapter;
|
||||
private final Gson gson;
|
||||
|
||||
GsonRequestBodyConverter(Gson gson, TypeAdapter<T> typeAdapter) {
|
||||
this.gson = gson;
|
||||
this.adapter = typeAdapter;
|
||||
}
|
||||
|
||||
/* JADX WARN: Multi-variable type inference failed */
|
||||
@Override // retrofit2.Converter
|
||||
public /* bridge */ /* synthetic */ RequestBody convert(Object obj) throws IOException {
|
||||
return convert((GsonRequestBodyConverter<T>) obj);
|
||||
}
|
||||
|
||||
@Override // retrofit2.Converter
|
||||
public RequestBody convert(T t) throws IOException {
|
||||
Buffer buffer = new Buffer();
|
||||
JsonWriter newJsonWriter = this.gson.newJsonWriter(new OutputStreamWriter(buffer.outputStream(), UTF_8));
|
||||
this.adapter.write(newJsonWriter, t);
|
||||
newJsonWriter.close();
|
||||
return RequestBody.create(MEDIA_TYPE, buffer.readByteString());
|
||||
}
|
||||
}
|
@@ -0,0 +1,35 @@
|
||||
package retrofit2.converter.gson;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonIOException;
|
||||
import com.google.gson.TypeAdapter;
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import com.google.gson.stream.JsonToken;
|
||||
import java.io.IOException;
|
||||
import okhttp3.ResponseBody;
|
||||
import retrofit2.Converter;
|
||||
|
||||
/* loaded from: classes2.dex */
|
||||
final class GsonResponseBodyConverter<T> implements Converter<ResponseBody, T> {
|
||||
private final TypeAdapter<T> adapter;
|
||||
private final Gson gson;
|
||||
|
||||
GsonResponseBodyConverter(Gson gson, TypeAdapter<T> typeAdapter) {
|
||||
this.gson = gson;
|
||||
this.adapter = typeAdapter;
|
||||
}
|
||||
|
||||
@Override // retrofit2.Converter
|
||||
public T convert(ResponseBody responseBody) throws IOException {
|
||||
JsonReader newJsonReader = this.gson.newJsonReader(responseBody.charStream());
|
||||
try {
|
||||
T read = this.adapter.read(newJsonReader);
|
||||
if (newJsonReader.peek() == JsonToken.END_DOCUMENT) {
|
||||
return read;
|
||||
}
|
||||
throw new JsonIOException("JSON document was not fully consumed.");
|
||||
} finally {
|
||||
responseBody.close();
|
||||
}
|
||||
}
|
||||
}
|
3
sources/retrofit2/converter/gson/package-info.java
Normal file
3
sources/retrofit2/converter/gson/package-info.java
Normal file
@@ -0,0 +1,3 @@
|
||||
|
||||
package retrofit2.converter.gson;
|
||||
|
Reference in New Issue
Block a user