jimu-decompiled/sources/retrofit2/converter/gson/GsonRequestBodyConverter.java
2025-05-13 19:24:51 +02:00

41 lines
1.5 KiB
Java

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());
}
}