Initial commit
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user