295 lines
12 KiB
Java
295 lines
12 KiB
Java
|
package com.google.gson;
|
||
|
|
||
|
import com.google.gson.internal.C$Gson$Preconditions;
|
||
|
import com.google.gson.internal.Excluder;
|
||
|
import com.google.gson.internal.bind.DefaultDateTypeAdapter;
|
||
|
import com.google.gson.internal.bind.TreeTypeAdapter;
|
||
|
import com.google.gson.internal.bind.TypeAdapters;
|
||
|
import com.google.gson.internal.sql.SqlTypesSupport;
|
||
|
import com.google.gson.reflect.TypeToken;
|
||
|
import java.lang.reflect.Type;
|
||
|
import java.util.ArrayList;
|
||
|
import java.util.Collections;
|
||
|
import java.util.HashMap;
|
||
|
import java.util.List;
|
||
|
import java.util.Map;
|
||
|
|
||
|
/* loaded from: classes.dex */
|
||
|
public final class GsonBuilder {
|
||
|
private boolean complexMapKeySerialization;
|
||
|
private String datePattern;
|
||
|
private int dateStyle;
|
||
|
private boolean escapeHtmlChars;
|
||
|
private Excluder excluder;
|
||
|
private final List<TypeAdapterFactory> factories;
|
||
|
private FieldNamingStrategy fieldNamingPolicy;
|
||
|
private boolean generateNonExecutableJson;
|
||
|
private final List<TypeAdapterFactory> hierarchyFactories;
|
||
|
private final Map<Type, InstanceCreator<?>> instanceCreators;
|
||
|
private boolean lenient;
|
||
|
private LongSerializationPolicy longSerializationPolicy;
|
||
|
private ToNumberStrategy numberToNumberStrategy;
|
||
|
private ToNumberStrategy objectToNumberStrategy;
|
||
|
private boolean prettyPrinting;
|
||
|
private boolean serializeNulls;
|
||
|
private boolean serializeSpecialFloatingPointValues;
|
||
|
private int timeStyle;
|
||
|
|
||
|
public GsonBuilder() {
|
||
|
this.excluder = Excluder.DEFAULT;
|
||
|
this.longSerializationPolicy = LongSerializationPolicy.DEFAULT;
|
||
|
this.fieldNamingPolicy = FieldNamingPolicy.IDENTITY;
|
||
|
this.instanceCreators = new HashMap();
|
||
|
this.factories = new ArrayList();
|
||
|
this.hierarchyFactories = new ArrayList();
|
||
|
this.serializeNulls = false;
|
||
|
this.dateStyle = 2;
|
||
|
this.timeStyle = 2;
|
||
|
this.complexMapKeySerialization = false;
|
||
|
this.serializeSpecialFloatingPointValues = false;
|
||
|
this.escapeHtmlChars = true;
|
||
|
this.prettyPrinting = false;
|
||
|
this.generateNonExecutableJson = false;
|
||
|
this.lenient = false;
|
||
|
this.objectToNumberStrategy = ToNumberPolicy.DOUBLE;
|
||
|
this.numberToNumberStrategy = ToNumberPolicy.LAZILY_PARSED_NUMBER;
|
||
|
}
|
||
|
|
||
|
/* JADX INFO: Access modifiers changed from: package-private */
|
||
|
public GsonBuilder(Gson gson) {
|
||
|
this.excluder = Excluder.DEFAULT;
|
||
|
this.longSerializationPolicy = LongSerializationPolicy.DEFAULT;
|
||
|
this.fieldNamingPolicy = FieldNamingPolicy.IDENTITY;
|
||
|
HashMap hashMap = new HashMap();
|
||
|
this.instanceCreators = hashMap;
|
||
|
ArrayList arrayList = new ArrayList();
|
||
|
this.factories = arrayList;
|
||
|
ArrayList arrayList2 = new ArrayList();
|
||
|
this.hierarchyFactories = arrayList2;
|
||
|
this.serializeNulls = false;
|
||
|
this.dateStyle = 2;
|
||
|
this.timeStyle = 2;
|
||
|
this.complexMapKeySerialization = false;
|
||
|
this.serializeSpecialFloatingPointValues = false;
|
||
|
this.escapeHtmlChars = true;
|
||
|
this.prettyPrinting = false;
|
||
|
this.generateNonExecutableJson = false;
|
||
|
this.lenient = false;
|
||
|
this.objectToNumberStrategy = ToNumberPolicy.DOUBLE;
|
||
|
this.numberToNumberStrategy = ToNumberPolicy.LAZILY_PARSED_NUMBER;
|
||
|
this.excluder = gson.excluder;
|
||
|
this.fieldNamingPolicy = gson.fieldNamingStrategy;
|
||
|
hashMap.putAll(gson.instanceCreators);
|
||
|
this.serializeNulls = gson.serializeNulls;
|
||
|
this.complexMapKeySerialization = gson.complexMapKeySerialization;
|
||
|
this.generateNonExecutableJson = gson.generateNonExecutableJson;
|
||
|
this.escapeHtmlChars = gson.htmlSafe;
|
||
|
this.prettyPrinting = gson.prettyPrinting;
|
||
|
this.lenient = gson.lenient;
|
||
|
this.serializeSpecialFloatingPointValues = gson.serializeSpecialFloatingPointValues;
|
||
|
this.longSerializationPolicy = gson.longSerializationPolicy;
|
||
|
this.datePattern = gson.datePattern;
|
||
|
this.dateStyle = gson.dateStyle;
|
||
|
this.timeStyle = gson.timeStyle;
|
||
|
arrayList.addAll(gson.builderFactories);
|
||
|
arrayList2.addAll(gson.builderHierarchyFactories);
|
||
|
this.objectToNumberStrategy = gson.objectToNumberStrategy;
|
||
|
this.numberToNumberStrategy = gson.numberToNumberStrategy;
|
||
|
}
|
||
|
|
||
|
public final GsonBuilder setVersion(double d) {
|
||
|
this.excluder = this.excluder.withVersion(d);
|
||
|
return this;
|
||
|
}
|
||
|
|
||
|
public final GsonBuilder excludeFieldsWithModifiers(int... iArr) {
|
||
|
this.excluder = this.excluder.withModifiers(iArr);
|
||
|
return this;
|
||
|
}
|
||
|
|
||
|
public final GsonBuilder excludeFieldsWithoutExposeAnnotation() {
|
||
|
this.excluder = this.excluder.excludeFieldsWithoutExposeAnnotation();
|
||
|
return this;
|
||
|
}
|
||
|
|
||
|
public final GsonBuilder disableInnerClassSerialization() {
|
||
|
this.excluder = this.excluder.disableInnerClassSerialization();
|
||
|
return this;
|
||
|
}
|
||
|
|
||
|
public final GsonBuilder setExclusionStrategies(ExclusionStrategy... exclusionStrategyArr) {
|
||
|
for (ExclusionStrategy exclusionStrategy : exclusionStrategyArr) {
|
||
|
this.excluder = this.excluder.withExclusionStrategy(exclusionStrategy, true, true);
|
||
|
}
|
||
|
return this;
|
||
|
}
|
||
|
|
||
|
public final GsonBuilder addSerializationExclusionStrategy(ExclusionStrategy exclusionStrategy) {
|
||
|
this.excluder = this.excluder.withExclusionStrategy(exclusionStrategy, true, false);
|
||
|
return this;
|
||
|
}
|
||
|
|
||
|
public final GsonBuilder addDeserializationExclusionStrategy(ExclusionStrategy exclusionStrategy) {
|
||
|
this.excluder = this.excluder.withExclusionStrategy(exclusionStrategy, false, true);
|
||
|
return this;
|
||
|
}
|
||
|
|
||
|
public final GsonBuilder registerTypeAdapter(Type type, Object obj) {
|
||
|
boolean z = obj instanceof JsonSerializer;
|
||
|
C$Gson$Preconditions.checkArgument(z || (obj instanceof JsonDeserializer) || (obj instanceof InstanceCreator) || (obj instanceof TypeAdapter));
|
||
|
if (obj instanceof InstanceCreator) {
|
||
|
this.instanceCreators.put(type, (InstanceCreator) obj);
|
||
|
}
|
||
|
if (z || (obj instanceof JsonDeserializer)) {
|
||
|
this.factories.add(TreeTypeAdapter.newFactoryWithMatchRawType(TypeToken.get(type), obj));
|
||
|
}
|
||
|
if (obj instanceof TypeAdapter) {
|
||
|
this.factories.add(TypeAdapters.newFactory(TypeToken.get(type), (TypeAdapter) obj));
|
||
|
}
|
||
|
return this;
|
||
|
}
|
||
|
|
||
|
public final GsonBuilder registerTypeAdapterFactory(TypeAdapterFactory typeAdapterFactory) {
|
||
|
this.factories.add(typeAdapterFactory);
|
||
|
return this;
|
||
|
}
|
||
|
|
||
|
public final GsonBuilder registerTypeHierarchyAdapter(Class<?> cls, Object obj) {
|
||
|
boolean z = obj instanceof JsonSerializer;
|
||
|
C$Gson$Preconditions.checkArgument(z || (obj instanceof JsonDeserializer) || (obj instanceof TypeAdapter));
|
||
|
if ((obj instanceof JsonDeserializer) || z) {
|
||
|
this.hierarchyFactories.add(TreeTypeAdapter.newTypeHierarchyFactory(cls, obj));
|
||
|
}
|
||
|
if (obj instanceof TypeAdapter) {
|
||
|
this.factories.add(TypeAdapters.newTypeHierarchyFactory(cls, (TypeAdapter) obj));
|
||
|
}
|
||
|
return this;
|
||
|
}
|
||
|
|
||
|
public final Gson create() {
|
||
|
List<TypeAdapterFactory> arrayList = new ArrayList<>(this.factories.size() + this.hierarchyFactories.size() + 3);
|
||
|
arrayList.addAll(this.factories);
|
||
|
Collections.reverse(arrayList);
|
||
|
ArrayList arrayList2 = new ArrayList(this.hierarchyFactories);
|
||
|
Collections.reverse(arrayList2);
|
||
|
arrayList.addAll(arrayList2);
|
||
|
addTypeAdaptersForDate(this.datePattern, this.dateStyle, this.timeStyle, arrayList);
|
||
|
return new Gson(this.excluder, this.fieldNamingPolicy, this.instanceCreators, this.serializeNulls, this.complexMapKeySerialization, this.generateNonExecutableJson, this.escapeHtmlChars, this.prettyPrinting, this.lenient, this.serializeSpecialFloatingPointValues, this.longSerializationPolicy, this.datePattern, this.dateStyle, this.timeStyle, this.factories, this.hierarchyFactories, arrayList, this.objectToNumberStrategy, this.numberToNumberStrategy);
|
||
|
}
|
||
|
|
||
|
private void addTypeAdaptersForDate(String str, int i, int i2, List<TypeAdapterFactory> list) {
|
||
|
TypeAdapterFactory typeAdapterFactory;
|
||
|
TypeAdapterFactory typeAdapterFactory2;
|
||
|
TypeAdapterFactory typeAdapterFactory3;
|
||
|
boolean z = SqlTypesSupport.SUPPORTS_SQL_TYPES;
|
||
|
if (str != null && !str.trim().isEmpty()) {
|
||
|
typeAdapterFactory = DefaultDateTypeAdapter.DateType.DATE.createAdapterFactory(str);
|
||
|
if (z) {
|
||
|
typeAdapterFactory2 = SqlTypesSupport.TIMESTAMP_DATE_TYPE.createAdapterFactory(str);
|
||
|
typeAdapterFactory3 = SqlTypesSupport.DATE_DATE_TYPE.createAdapterFactory(str);
|
||
|
}
|
||
|
typeAdapterFactory2 = null;
|
||
|
typeAdapterFactory3 = null;
|
||
|
} else {
|
||
|
if (i == 2 || i2 == 2) {
|
||
|
return;
|
||
|
}
|
||
|
TypeAdapterFactory createAdapterFactory = DefaultDateTypeAdapter.DateType.DATE.createAdapterFactory(i, i2);
|
||
|
if (z) {
|
||
|
TypeAdapterFactory createAdapterFactory2 = SqlTypesSupport.TIMESTAMP_DATE_TYPE.createAdapterFactory(i, i2);
|
||
|
TypeAdapterFactory createAdapterFactory3 = SqlTypesSupport.DATE_DATE_TYPE.createAdapterFactory(i, i2);
|
||
|
typeAdapterFactory2 = createAdapterFactory2;
|
||
|
typeAdapterFactory = createAdapterFactory;
|
||
|
typeAdapterFactory3 = createAdapterFactory3;
|
||
|
} else {
|
||
|
typeAdapterFactory = createAdapterFactory;
|
||
|
typeAdapterFactory2 = null;
|
||
|
typeAdapterFactory3 = null;
|
||
|
}
|
||
|
}
|
||
|
list.add(typeAdapterFactory);
|
||
|
if (z) {
|
||
|
list.add(typeAdapterFactory2);
|
||
|
list.add(typeAdapterFactory3);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public final GsonBuilder setPrettyPrinting() {
|
||
|
this.prettyPrinting = true;
|
||
|
return this;
|
||
|
}
|
||
|
|
||
|
public final GsonBuilder setObjectToNumberStrategy(ToNumberStrategy toNumberStrategy) {
|
||
|
this.objectToNumberStrategy = toNumberStrategy;
|
||
|
return this;
|
||
|
}
|
||
|
|
||
|
public final GsonBuilder setNumberToNumberStrategy(ToNumberStrategy toNumberStrategy) {
|
||
|
this.numberToNumberStrategy = toNumberStrategy;
|
||
|
return this;
|
||
|
}
|
||
|
|
||
|
public final GsonBuilder setLongSerializationPolicy(LongSerializationPolicy longSerializationPolicy) {
|
||
|
this.longSerializationPolicy = longSerializationPolicy;
|
||
|
return this;
|
||
|
}
|
||
|
|
||
|
public final GsonBuilder setLenient() {
|
||
|
this.lenient = true;
|
||
|
return this;
|
||
|
}
|
||
|
|
||
|
public final GsonBuilder setFieldNamingStrategy(FieldNamingStrategy fieldNamingStrategy) {
|
||
|
this.fieldNamingPolicy = fieldNamingStrategy;
|
||
|
return this;
|
||
|
}
|
||
|
|
||
|
public final GsonBuilder setFieldNamingPolicy(FieldNamingPolicy fieldNamingPolicy) {
|
||
|
this.fieldNamingPolicy = fieldNamingPolicy;
|
||
|
return this;
|
||
|
}
|
||
|
|
||
|
public final GsonBuilder setDateFormat(String str) {
|
||
|
this.datePattern = str;
|
||
|
return this;
|
||
|
}
|
||
|
|
||
|
public final GsonBuilder setDateFormat(int i, int i2) {
|
||
|
this.dateStyle = i;
|
||
|
this.timeStyle = i2;
|
||
|
this.datePattern = null;
|
||
|
return this;
|
||
|
}
|
||
|
|
||
|
public final GsonBuilder setDateFormat(int i) {
|
||
|
this.dateStyle = i;
|
||
|
this.datePattern = null;
|
||
|
return this;
|
||
|
}
|
||
|
|
||
|
public final GsonBuilder serializeSpecialFloatingPointValues() {
|
||
|
this.serializeSpecialFloatingPointValues = true;
|
||
|
return this;
|
||
|
}
|
||
|
|
||
|
public final GsonBuilder serializeNulls() {
|
||
|
this.serializeNulls = true;
|
||
|
return this;
|
||
|
}
|
||
|
|
||
|
public final GsonBuilder generateNonExecutableJson() {
|
||
|
this.generateNonExecutableJson = true;
|
||
|
return this;
|
||
|
}
|
||
|
|
||
|
public final GsonBuilder enableComplexMapKeySerialization() {
|
||
|
this.complexMapKeySerialization = true;
|
||
|
return this;
|
||
|
}
|
||
|
|
||
|
public final GsonBuilder disableHtmlEscaping() {
|
||
|
this.escapeHtmlChars = false;
|
||
|
return this;
|
||
|
}
|
||
|
}
|