what-the-bank/sources/com/google/firebase/encoders/json/JsonDataEncoderBuilder.java

160 lines
6.5 KiB
Java
Raw Normal View History

2024-07-27 18:17:47 +07:00
package com.google.firebase.encoders.json;
import com.google.firebase.encoders.DataEncoder;
import com.google.firebase.encoders.EncodingException;
import com.google.firebase.encoders.ObjectEncoder;
import com.google.firebase.encoders.ObjectEncoderContext;
import com.google.firebase.encoders.ValueEncoder;
import com.google.firebase.encoders.ValueEncoderContext;
import com.google.firebase.encoders.config.Configurator;
import com.google.firebase.encoders.config.EncoderConfig;
import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.TimeZone;
/* loaded from: classes.dex */
public final class JsonDataEncoderBuilder implements EncoderConfig<JsonDataEncoderBuilder> {
private static final ValueEncoder<Boolean> BOOLEAN_ENCODER;
private static final ObjectEncoder<Object> DEFAULT_FALLBACK_ENCODER;
private static final ValueEncoder<String> STRING_ENCODER;
private static final TimestampEncoder TIMESTAMP_ENCODER;
private final Map<Class<?>, ObjectEncoder<?>> objectEncoders = new HashMap();
private final Map<Class<?>, ValueEncoder<?>> valueEncoders = new HashMap();
private ObjectEncoder<Object> fallbackEncoder = DEFAULT_FALLBACK_ENCODER;
private boolean ignoreNullValues = false;
static {
ObjectEncoder<Object> objectEncoder;
ValueEncoder<String> valueEncoder;
ValueEncoder<Boolean> valueEncoder2;
objectEncoder = JsonDataEncoderBuilder$$Lambda$1.instance;
DEFAULT_FALLBACK_ENCODER = objectEncoder;
valueEncoder = JsonDataEncoderBuilder$$Lambda$4.instance;
STRING_ENCODER = valueEncoder;
valueEncoder2 = JsonDataEncoderBuilder$$Lambda$5.instance;
BOOLEAN_ENCODER = valueEncoder2;
TIMESTAMP_ENCODER = new TimestampEncoder();
}
public static /* synthetic */ void lambda$static$0(Object obj, ObjectEncoderContext objectEncoderContext) throws IOException {
StringBuilder sb = new StringBuilder("Couldn't find encoder for type ");
sb.append(obj.getClass().getCanonicalName());
throw new EncodingException(sb.toString());
}
/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes.dex */
public static final class TimestampEncoder implements ValueEncoder<Date> {
private static final DateFormat rfc339;
private TimestampEncoder() {
}
/* synthetic */ TimestampEncoder(AnonymousClass1 anonymousClass1) {
this();
}
static {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.US);
rfc339 = simpleDateFormat;
simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
}
@Override // com.google.firebase.encoders.Encoder
public final void encode(Date date, ValueEncoderContext valueEncoderContext) throws IOException {
valueEncoderContext.add(rfc339.format(date));
}
}
public JsonDataEncoderBuilder() {
registerEncoder(String.class, STRING_ENCODER);
registerEncoder(Boolean.class, BOOLEAN_ENCODER);
registerEncoder(Date.class, TIMESTAMP_ENCODER);
}
@Override // com.google.firebase.encoders.config.EncoderConfig
public final <T> JsonDataEncoderBuilder registerEncoder(Class<T> cls, ObjectEncoder<? super T> objectEncoder) {
this.objectEncoders.put(cls, objectEncoder);
this.valueEncoders.remove(cls);
return this;
}
public final <T> JsonDataEncoderBuilder registerEncoder(Class<T> cls, ValueEncoder<? super T> valueEncoder) {
this.valueEncoders.put(cls, valueEncoder);
this.objectEncoders.remove(cls);
return this;
}
public final JsonDataEncoderBuilder configureWith(Configurator configurator) {
configurator.configure(this);
return this;
}
/* JADX INFO: Access modifiers changed from: package-private */
/* renamed from: com.google.firebase.encoders.json.JsonDataEncoderBuilder$1 */
/* loaded from: classes.dex */
public class AnonymousClass1 implements DataEncoder {
final JsonDataEncoderBuilder this$0;
AnonymousClass1(JsonDataEncoderBuilder jsonDataEncoderBuilder) {
this.this$0 = jsonDataEncoderBuilder;
}
@Override // com.google.firebase.encoders.DataEncoder
public void encode(Object obj, Writer writer) throws IOException {
JsonValueObjectEncoderContext jsonValueObjectEncoderContext = new JsonValueObjectEncoderContext(writer, this.this$0.objectEncoders, this.this$0.valueEncoders, this.this$0.fallbackEncoder, this.this$0.ignoreNullValues);
jsonValueObjectEncoderContext.add(obj, false);
jsonValueObjectEncoderContext.close();
}
@Override // com.google.firebase.encoders.DataEncoder
public String encode(Object obj) {
StringWriter stringWriter = new StringWriter();
try {
encode(obj, stringWriter);
} catch (IOException unused) {
}
return stringWriter.toString();
}
}
public final DataEncoder build() {
return new DataEncoder(this) { // from class: com.google.firebase.encoders.json.JsonDataEncoderBuilder.1
final JsonDataEncoderBuilder this$0;
AnonymousClass1(JsonDataEncoderBuilder this) {
this.this$0 = this;
}
@Override // com.google.firebase.encoders.DataEncoder
public void encode(Object obj, Writer writer) throws IOException {
JsonValueObjectEncoderContext jsonValueObjectEncoderContext = new JsonValueObjectEncoderContext(writer, this.this$0.objectEncoders, this.this$0.valueEncoders, this.this$0.fallbackEncoder, this.this$0.ignoreNullValues);
jsonValueObjectEncoderContext.add(obj, false);
jsonValueObjectEncoderContext.close();
}
@Override // com.google.firebase.encoders.DataEncoder
public String encode(Object obj) {
StringWriter stringWriter = new StringWriter();
try {
encode(obj, stringWriter);
} catch (IOException unused) {
}
return stringWriter.toString();
}
};
}
public final JsonDataEncoderBuilder ignoreNullValues(boolean z) {
this.ignoreNullValues = z;
return this;
}
}