2021-06-27 20:44:35 +00:00
|
|
|
package com.google.gson;
|
|
|
|
|
|
|
|
import c.i.d.q.x.a;
|
|
|
|
import c.i.d.q.x.b;
|
|
|
|
import com.google.gson.stream.JsonReader;
|
|
|
|
import com.google.gson.stream.JsonToken;
|
|
|
|
import com.google.gson.stream.JsonWriter;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.Reader;
|
|
|
|
import java.io.StringReader;
|
|
|
|
import java.io.StringWriter;
|
|
|
|
import java.io.Writer;
|
|
|
|
public abstract class TypeAdapter<T> {
|
|
|
|
|
|
|
|
/* renamed from: com.google.gson.TypeAdapter$1 reason: invalid class name */
|
|
|
|
public class AnonymousClass1 extends TypeAdapter<T> {
|
|
|
|
public AnonymousClass1() {
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override // com.google.gson.TypeAdapter
|
|
|
|
public T read(JsonReader jsonReader) throws IOException {
|
|
|
|
if (jsonReader.N() != JsonToken.NULL) {
|
|
|
|
return (T) TypeAdapter.this.read(jsonReader);
|
|
|
|
}
|
|
|
|
jsonReader.H();
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override // com.google.gson.TypeAdapter
|
|
|
|
public void write(JsonWriter jsonWriter, T t) throws IOException {
|
|
|
|
if (t == null) {
|
|
|
|
jsonWriter.s();
|
|
|
|
} else {
|
|
|
|
TypeAdapter.this.write(jsonWriter, t);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public final T fromJson(Reader reader) throws IOException {
|
|
|
|
return read(new JsonReader(reader));
|
|
|
|
}
|
|
|
|
|
|
|
|
public final T fromJson(String str) throws IOException {
|
|
|
|
return fromJson(new StringReader(str));
|
|
|
|
}
|
|
|
|
|
|
|
|
public final T fromJsonTree(JsonElement jsonElement) {
|
|
|
|
try {
|
|
|
|
return read(new a(jsonElement));
|
|
|
|
} catch (IOException e) {
|
|
|
|
throw new JsonIOException(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public final TypeAdapter<T> nullSafe() {
|
|
|
|
return new AnonymousClass1();
|
|
|
|
}
|
|
|
|
|
|
|
|
public abstract T read(JsonReader jsonReader) throws IOException;
|
|
|
|
|
|
|
|
public final String toJson(T t) {
|
|
|
|
StringWriter stringWriter = new StringWriter();
|
|
|
|
try {
|
|
|
|
toJson(stringWriter, t);
|
|
|
|
return stringWriter.toString();
|
|
|
|
} catch (IOException e) {
|
|
|
|
throw new AssertionError(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public final void toJson(Writer writer, T t) throws IOException {
|
|
|
|
write(new JsonWriter(writer), t);
|
|
|
|
}
|
|
|
|
|
|
|
|
public final JsonElement toJsonTree(T t) {
|
|
|
|
try {
|
|
|
|
b bVar = new b();
|
|
|
|
write(bVar, t);
|
|
|
|
if (bVar.v.isEmpty()) {
|
2021-07-13 20:23:20 +00:00
|
|
|
return bVar.f1388x;
|
2021-06-27 20:44:35 +00:00
|
|
|
}
|
|
|
|
throw new IllegalStateException("Expected one JSON element but was " + bVar.v);
|
|
|
|
} catch (IOException e) {
|
|
|
|
throw new JsonIOException(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public abstract void write(JsonWriter jsonWriter, T t) throws IOException;
|
|
|
|
}
|