📄 defaulttypeadapters.java
字号:
public String toString() { return MapTypeAdapter.class.getSimpleName(); } } private static class BigDecimalTypeAdapter implements JsonSerializer<BigDecimal>, JsonDeserializer<BigDecimal> { public JsonElement serialize(BigDecimal src, Type typeOfSrc, JsonSerializationContext context) { return new JsonPrimitive(src); } public BigDecimal deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { return json.getAsBigDecimal(); } @Override public String toString() { return BigDecimalTypeAdapter.class.getSimpleName(); } } private static class BigIntegerTypeAdapter implements JsonSerializer<BigInteger>, JsonDeserializer<BigInteger> { public JsonElement serialize(BigInteger src, Type typeOfSrc, JsonSerializationContext context) { return new JsonPrimitive(src); } public BigInteger deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { return json.getAsBigInteger(); } @Override public String toString() { return BigIntegerTypeAdapter.class.getSimpleName(); } } private static class NumberTypeAdapter implements JsonSerializer<Number>, JsonDeserializer<Number> { public JsonElement serialize(Number src, Type typeOfSrc, JsonSerializationContext context) { return new JsonPrimitive(src); } public Number deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { return json.getAsNumber(); } @Override public String toString() { return NumberTypeAdapter.class.getSimpleName(); } } private static class LongSerializer implements JsonSerializer<Long> { private final LongSerializationPolicy longSerializationPolicy; private LongSerializer(LongSerializationPolicy longSerializationPolicy) { this.longSerializationPolicy = longSerializationPolicy; } public JsonElement serialize(Long src, Type typeOfSrc, JsonSerializationContext context) { return longSerializationPolicy.serialize(src); } @Override public String toString() { return LongSerializer.class.getSimpleName(); } } private static class LongDeserializer implements JsonDeserializer<Long> { public Long deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { return json.getAsLong(); } @Override public String toString() { return LongDeserializer.class.getSimpleName(); } } private static class IntegerTypeAdapter implements JsonSerializer<Integer>, JsonDeserializer<Integer> { public JsonElement serialize(Integer src, Type typeOfSrc, JsonSerializationContext context) { return new JsonPrimitive(src); } public Integer deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { return json.getAsInt(); } @Override public String toString() { return IntegerTypeAdapter.class.getSimpleName(); } } private static class ShortTypeAdapter implements JsonSerializer<Short>, JsonDeserializer<Short> { public JsonElement serialize(Short src, Type typeOfSrc, JsonSerializationContext context) { return new JsonPrimitive(src); } public Short deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { return json.getAsShort(); } @Override public String toString() { return ShortTypeAdapter.class.getSimpleName(); } } private static class ByteTypeAdapter implements JsonSerializer<Byte>, JsonDeserializer<Byte> { public JsonElement serialize(Byte src, Type typeOfSrc, JsonSerializationContext context) { return new JsonPrimitive(src); } public Byte deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { return json.getAsByte(); } @Override public String toString() { return ByteTypeAdapter.class.getSimpleName(); } } static class FloatSerializer implements JsonSerializer<Float> { private final boolean serializeSpecialFloatingPointValues; FloatSerializer(boolean serializeSpecialDoubleValues) { this.serializeSpecialFloatingPointValues = serializeSpecialDoubleValues; } public JsonElement serialize(Float src, Type typeOfSrc, JsonSerializationContext context) { if (!serializeSpecialFloatingPointValues) { if (Float.isNaN(src) || Float.isInfinite(src)) { throw new IllegalArgumentException(src + " is not a valid float value as per JSON specification. To override this" + " behavior, use GsonBuilder.serializeSpecialFloatingPointValues() method."); } } return new JsonPrimitive(src); } } private static class FloatDeserializer implements JsonDeserializer<Float> { public Float deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { return json.getAsFloat(); } @Override public String toString() { return FloatDeserializer.class.getSimpleName(); } } static class DoubleSerializer implements JsonSerializer<Double> { private final boolean serializeSpecialFloatingPointValues; DoubleSerializer(boolean serializeSpecialDoubleValues) { this.serializeSpecialFloatingPointValues = serializeSpecialDoubleValues; } public JsonElement serialize(Double src, Type typeOfSrc, JsonSerializationContext context) { if (!serializeSpecialFloatingPointValues) { if (Double.isNaN(src) || Double.isInfinite(src)) { throw new IllegalArgumentException(src + " is not a valid double value as per JSON specification. To override this" + " behavior, use GsonBuilder.serializeSpecialDoubleValues() method."); } } return new JsonPrimitive(src); } } private static class DoubleDeserializer implements JsonDeserializer<Double> { public Double deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { return json.getAsDouble(); } @Override public String toString() { return DoubleDeserializer.class.getSimpleName(); } } private static class CharacterTypeAdapter implements JsonSerializer<Character>, JsonDeserializer<Character> { public JsonElement serialize(Character src, Type typeOfSrc, JsonSerializationContext context) { return new JsonPrimitive(src); } public Character deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { return json.getAsCharacter(); } @Override public String toString() { return CharacterTypeAdapter.class.getSimpleName(); } } private static class StringTypeAdapter implements JsonSerializer<String>, JsonDeserializer<String> { public JsonElement serialize(String src, Type typeOfSrc, JsonSerializationContext context) { return new JsonPrimitive(src); } public String deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { return json.getAsString(); } @Override public String toString() { return StringTypeAdapter.class.getSimpleName(); } } private static class BooleanTypeAdapter implements JsonSerializer<Boolean>, JsonDeserializer<Boolean> { public JsonElement serialize(Boolean src, Type typeOfSrc, JsonSerializationContext context) { return new JsonPrimitive(src); } public Boolean deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { return json.getAsBoolean(); } @Override public String toString() { return BooleanTypeAdapter.class.getSimpleName(); } } private static class TreeSetCreator implements InstanceCreator<TreeSet<?>> { public TreeSet<?> createInstance(Type type) { return new TreeSet<Object>(); } @Override public String toString() { return TreeSetCreator.class.getSimpleName(); } } private static class HashSetCreator implements InstanceCreator<HashSet<?>> { public HashSet<?> createInstance(Type type) { return new HashSet<Object>(); } @Override public String toString() { return HashSetCreator.class.getSimpleName(); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -