private TypeAdapter<Number> doubleAdapter(boolean serializeSpecialFloatingPointValues) { if (serializeSpecialFloatingPointValues) { return TypeAdapters.DOUBLE; } return new TypeAdapter<Number>() { public Double read(JsonReader in) throws IOException { if (in.peek() != JsonToken.NULL) { return Double.valueOf(in.nextDouble()); } in.nextNull(); return null; } public void write(JsonWriter out, Number value) throws IOException { if (value == null) { out.nullValue(); return; } Gson.this.checkValidFloatingPoint(value.doubleValue()); out.value(value); } }; }
private TypeAdapter<Number> floatAdapter(boolean serializeSpecialFloatingPointValues) { if (serializeSpecialFloatingPointValues) { return TypeAdapters.FLOAT; } return new TypeAdapter<Number>() { public Float read(JsonReader in) throws IOException { if (in.peek() != JsonToken.NULL) { return Float.valueOf((float) in.nextDouble()); } in.nextNull(); return null; } public void write(JsonWriter out, Number value) throws IOException { if (value == null) { out.nullValue(); return; } Gson.this.checkValidFloatingPoint((double) value.floatValue()); out.value(value); } }; }
private TypeAdapter<Number> longAdapter(LongSerializationPolicy longSerializationPolicy) { if (longSerializationPolicy == LongSerializationPolicy.DEFAULT) { return TypeAdapters.LONG; } return new TypeAdapter<Number>() { public Number read(JsonReader in) throws IOException { if (in.peek() != JsonToken.NULL) { return Long.valueOf(in.nextLong()); } in.nextNull(); return null; } public void write(JsonWriter out, Number value) throws IOException { if (value == null) { out.nullValue(); } else { out.value(value.toString()); } } }; }
public GsonBuilder registerTypeAdapter(Type type, Object typeAdapter) { boolean z = (typeAdapter instanceof JsonSerializer) || (typeAdapter instanceof JsonDeserializer) || (typeAdapter instanceof InstanceCreator) || (typeAdapter instanceof TypeAdapter); C$Gson$Preconditions.checkArgument(z); if (Primitives.isPrimitive(type) || Primitives.isWrapperType(type)) { throw new IllegalArgumentException("Cannot register type adapters for " + type); } if (typeAdapter instanceof InstanceCreator) { this.instanceCreators.put(type, (InstanceCreator) typeAdapter); } if ((typeAdapter instanceof JsonSerializer) || (typeAdapter instanceof JsonDeserializer)) { this.factories.add(TreeTypeAdapter.newFactoryWithMatchRawType(TypeToken.get(type), typeAdapter)); } if (typeAdapter instanceof TypeAdapter) { this.factories.add(TypeAdapters.newFactory(TypeToken.get(type), (TypeAdapter) typeAdapter)); } return this; }
public GsonBuilder registerTypeHierarchyAdapter(Class<?> baseType, Object typeAdapter) { boolean z; if ((typeAdapter instanceof JsonSerializer) || (typeAdapter instanceof JsonDeserializer) || (typeAdapter instanceof TypeAdapter)) { z = true; } else { z = false; } C$Gson$Preconditions.checkArgument(z); if ((typeAdapter instanceof JsonDeserializer) || (typeAdapter instanceof JsonSerializer)) { this.hierarchyFactories.add(0, TreeTypeAdapter.newTypeHierarchyFactory(baseType, typeAdapter)); } if (typeAdapter instanceof TypeAdapter) { this.factories.add(TypeAdapters.newTypeHierarchyFactory(baseType, (TypeAdapter) typeAdapter)); } return this; }
public static JsonElement parse(JsonReader reader) throws JsonParseException { boolean isEmpty = true; try { reader.peek(); isEmpty = false; return (JsonElement) TypeAdapters.JSON_ELEMENT.read(reader); } catch (Throwable e) { if (isEmpty) { return JsonNull.INSTANCE; } throw new JsonIOException(e); } catch (Throwable e2) { throw new JsonSyntaxException(e2); } catch (Throwable e22) { throw new JsonIOException(e22); } catch (Throwable e222) { throw new JsonSyntaxException(e222); } }
private TypeAdapter<Number> doubleAdapter(boolean serializeSpecialFloatingPointValues) { if (serializeSpecialFloatingPointValues) { return TypeAdapters.DOUBLE; } return new TypeAdapter<Number>() { @Override public Double read(JsonReader in) throws IOException { if (in.peek() == JsonToken.NULL) { in.nextNull(); return null; } return in.nextDouble(); } @Override public void write(JsonWriter out, Number value) throws IOException { if (value == null) { out.nullValue(); return; } double doubleValue = value.doubleValue(); checkValidFloatingPoint(doubleValue); out.value(value); } }; }
private TypeAdapter<Number> floatAdapter(boolean serializeSpecialFloatingPointValues) { if (serializeSpecialFloatingPointValues) { return TypeAdapters.FLOAT; } return new TypeAdapter<Number>() { @Override public Float read(JsonReader in) throws IOException { if (in.peek() == JsonToken.NULL) { in.nextNull(); return null; } return (float) in.nextDouble(); } @Override public void write(JsonWriter out, Number value) throws IOException { if (value == null) { out.nullValue(); return; } float floatValue = value.floatValue(); checkValidFloatingPoint(floatValue); out.value(value); } }; }
private TypeAdapter<Number> longAdapter(LongSerializationPolicy longSerializationPolicy) { if (longSerializationPolicy == LongSerializationPolicy.DEFAULT) { return TypeAdapters.LONG; } return new TypeAdapter<Number>() { @Override public Number read(JsonReader in) throws IOException { if (in.peek() == JsonToken.NULL) { in.nextNull(); return null; } return in.nextLong(); } @Override public void write(JsonWriter out, Number value) throws IOException { if (value == null) { out.nullValue(); return; } out.value(value.toString()); } }; }
/** * Configures Gson for custom serialization or deserialization. This method combines the * registration of an {@link TypeAdapter}, {@link InstanceCreator}, {@link JsonSerializer}, and a * {@link JsonDeserializer}. It is best used when a single object {@code typeAdapter} implements * all the required interfaces for custom serialization with Gson. If a type adapter was * previously registered for the specified {@code type}, it is overwritten. * * <p>This registers the type specified and no other types: you must manually register related * types! For example, applications registering {@code boolean.class} should also register {@code * Boolean.class}. * * @param type the type definition for the type adapter being registered * @param typeAdapter This object must implement at least one of the {@link TypeAdapter}, * {@link InstanceCreator}, {@link JsonSerializer}, and a {@link JsonDeserializer} interfaces. * @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern */ @SuppressWarnings({"unchecked", "rawtypes"}) public GsonBuilder registerTypeAdapter(Type type, Object typeAdapter) { $Gson$Preconditions.checkArgument(typeAdapter instanceof JsonSerializer<?> || typeAdapter instanceof JsonDeserializer<?> || typeAdapter instanceof InstanceCreator<?> || typeAdapter instanceof TypeAdapter<?>); if (typeAdapter instanceof InstanceCreator<?>) { instanceCreators.put(type, (InstanceCreator) typeAdapter); } if (typeAdapter instanceof JsonSerializer<?> || typeAdapter instanceof JsonDeserializer<?>) { TypeToken<?> typeToken = TypeToken.get(type); factories.add(TreeTypeAdapter.newFactoryWithMatchRawType(typeToken, typeAdapter)); } if (typeAdapter instanceof TypeAdapter<?>) { factories.add(TypeAdapters.newFactory(TypeToken.get(type), (TypeAdapter)typeAdapter)); } return this; }
public GsonBuilder registerTypeAdapter(Type type, Object typeAdapter) { boolean z = (typeAdapter instanceof JsonSerializer) || (typeAdapter instanceof JsonDeserializer) || (typeAdapter instanceof InstanceCreator) || (typeAdapter instanceof TypeAdapter); C$Gson$Preconditions.checkArgument(z); if (typeAdapter instanceof InstanceCreator) { this.instanceCreators.put(type, (InstanceCreator) typeAdapter); } if ((typeAdapter instanceof JsonSerializer) || (typeAdapter instanceof JsonDeserializer)) { this.factories.add(TreeTypeAdapter.newFactoryWithMatchRawType(TypeToken.get(type), typeAdapter)); } if (typeAdapter instanceof TypeAdapter) { this.factories.add(TypeAdapters.newFactory(TypeToken.get(type), (TypeAdapter) typeAdapter)); } return this; }
public static JsonElement parse(JsonReader reader) throws JsonParseException { boolean isEmpty = true; try { reader.peek(); isEmpty = false; return (JsonElement) TypeAdapters.JSON_ELEMENT.read(reader); } catch (Throwable e) { if (isEmpty) { return JsonNull.INSTANCE; } throw new JsonSyntaxException(e); } catch (Throwable e2) { throw new JsonSyntaxException(e2); } catch (Throwable e22) { throw new JsonIOException(e22); } catch (Throwable e222) { throw new JsonSyntaxException(e222); } }
private static TypeAdapter<Number> longAdapter(LongSerializationPolicy longSerializationPolicy) { if (longSerializationPolicy == LongSerializationPolicy.DEFAULT) { return TypeAdapters.LONG; } return new TypeAdapter<Number>() { @Override public Number read(JsonReader in) throws IOException { if (in.peek() == JsonToken.NULL) { in.nextNull(); return null; } return in.nextLong(); } @Override public void write(JsonWriter out, Number value) throws IOException { if (value == null) { out.nullValue(); return; } out.value(value.toString()); } }; }