what-the-bank/sources/retrofit2/converter/gson/GsonResponseBodyConverter.java

37 lines
1.2 KiB
Java

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: classes.dex */
final class GsonResponseBodyConverter<T> implements Converter<ResponseBody, T> {
private final TypeAdapter<T> adapter;
private final Gson gson;
/* JADX INFO: Access modifiers changed from: package-private */
public GsonResponseBodyConverter(Gson gson, TypeAdapter<T> typeAdapter) {
this.gson = gson;
this.adapter = typeAdapter;
}
@Override // retrofit2.Converter
public final T convert(ResponseBody responseBody) throws IOException {
JsonReader newJsonReader = this.gson.newJsonReader(responseBody.charStream());
try {
T read2 = this.adapter.read2(newJsonReader);
if (newJsonReader.peek() == JsonToken.END_DOCUMENT) {
return read2;
}
throw new JsonIOException("JSON document was not fully consumed.");
} finally {
responseBody.close();
}
}
}