package o; import com.google.gson.Gson; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.TypeAdapter; import com.google.gson.TypeAdapterFactory; import com.google.gson.reflect.TypeToken; import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; import java.io.IOException; import java.util.Map; /* loaded from: classes6.dex */ public final class fRC implements TypeAdapterFactory { private final Map, fRG> a; public fRC(Map, fRG> map) { this.a = map; } @Override // com.google.gson.TypeAdapterFactory public final TypeAdapter create(Gson gson, TypeToken typeToken) { fRG frg; TypeAdapter delegateAdapter = gson.getDelegateAdapter(this, typeToken); Class rawType = typeToken.getRawType(); while (true) { if (rawType == null) { frg = null; break; } frg = this.a.get(rawType); if (frg != null) { break; } rawType = rawType.getSuperclass(); } return frg == null ? delegateAdapter : new fRA(new LWm(this, frg, gson, delegateAdapter)); } /* loaded from: classes6.dex */ class LWm extends TypeAdapter { private final Gson a; private fRC b; private final fRG c; private final TypeAdapter d; public LWm(fRC frc, fRG frg, Gson gson, TypeAdapter typeAdapter) { this.b = frc; this.c = frg; this.a = gson; this.d = typeAdapter; } @Override // com.google.gson.TypeAdapter public final void write(JsonWriter jsonWriter, T t) throws IOException { if (t == null) { this.d.write(jsonWriter, t); return; } String b = this.c.b(); JsonElement jsonTree = this.d.toJsonTree(t); JsonObject jsonObject = new JsonObject(); jsonObject.add(b, jsonTree); this.a.toJson(jsonObject, jsonWriter); } @Override // com.google.gson.TypeAdapter /* renamed from: read */ public final T read2(JsonReader jsonReader) throws IOException { jsonReader.beginObject(); jsonReader.nextName(); T read2 = this.d.read2(jsonReader); jsonReader.endObject(); return read2; } } }