@Override public @Nullable JsonAdapter<?> create( Type type, Set<? extends Annotation> annotations, Moshi moshi) { Class<?> rawType = Types.getRawType(type); if (!annotations.isEmpty()) return null; if (rawType == List.class || rawType == Collection.class) { return newArrayListAdapter(type, moshi).nullSafe(); } else if (rawType == Set.class) { return newLinkedHashSetAdapter(type, moshi).nullSafe(); } return null; } };
if (type == long.class) return LONG_JSON_ADAPTER; if (type == short.class) return SHORT_JSON_ADAPTER; if (type == Boolean.class) return BOOLEAN_JSON_ADAPTER.nullSafe(); if (type == Byte.class) return BYTE_JSON_ADAPTER.nullSafe(); if (type == Character.class) return CHARACTER_JSON_ADAPTER.nullSafe(); if (type == Double.class) return DOUBLE_JSON_ADAPTER.nullSafe(); if (type == Float.class) return FLOAT_JSON_ADAPTER.nullSafe(); if (type == Integer.class) return INTEGER_JSON_ADAPTER.nullSafe(); if (type == Long.class) return LONG_JSON_ADAPTER.nullSafe(); if (type == Short.class) return SHORT_JSON_ADAPTER.nullSafe(); if (type == String.class) return STRING_JSON_ADAPTER.nullSafe(); if (type == Object.class) return new ObjectJsonAdapter(moshi).nullSafe();
constructor.setAccessible(true); return constructor.newInstance(moshi, ((ParameterizedType) type).getActualTypeArguments()) .nullSafe(); } else { Constructor<? extends JsonAdapter<?>> constructor = adapterClass.getDeclaredConstructor(Moshi.class); constructor.setAccessible(true); return constructor.newInstance(moshi).nullSafe();
@Override public @Nullable JsonAdapter<?> create( Type type, Set<? extends Annotation> annotations, Moshi moshi) { Class<?> rawType = Types.getRawType(type); if (!annotations.isEmpty()) return null; if (rawType == List.class || rawType == Collection.class) { return newArrayListAdapter(type, moshi).nullSafe(); } else if (rawType == Set.class) { return newLinkedHashSetAdapter(type, moshi).nullSafe(); } return null; } };
if (type == long.class) return LONG_JSON_ADAPTER; if (type == short.class) return SHORT_JSON_ADAPTER; if (type == Boolean.class) return BOOLEAN_JSON_ADAPTER.nullSafe(); if (type == Byte.class) return BYTE_JSON_ADAPTER.nullSafe(); if (type == Character.class) return CHARACTER_JSON_ADAPTER.nullSafe(); if (type == Double.class) return DOUBLE_JSON_ADAPTER.nullSafe(); if (type == Float.class) return FLOAT_JSON_ADAPTER.nullSafe(); if (type == Integer.class) return INTEGER_JSON_ADAPTER.nullSafe(); if (type == Long.class) return LONG_JSON_ADAPTER.nullSafe(); if (type == Short.class) return SHORT_JSON_ADAPTER.nullSafe(); if (type == String.class) return STRING_JSON_ADAPTER.nullSafe(); if (type == Object.class) return new ObjectJsonAdapter(moshi).nullSafe();
constructor.setAccessible(true); return constructor.newInstance(moshi, ((ParameterizedType) type).getActualTypeArguments()) .nullSafe(); } else { Constructor<? extends JsonAdapter<?>> constructor = adapterClass.getDeclaredConstructor(Moshi.class); constructor.setAccessible(true); return constructor.newInstance(moshi).nullSafe();
@Override public JsonAdapter<?> create(Type type, Set<? extends Annotation> annotations, Moshi moshi) { if (annotations.isEmpty() || annotations.size() != 1 // At this point we know that the set contains only one entry. || annotations.iterator().next().annotationType() != CsvCollection.class) { return null; } Class<?> rawType = Types.getRawType(type); // This adapter supports only List<String>, Collection<String> and Set<String>. if ((rawType == List.class || rawType == Collection.class) && elementTypeIsString(type)) { return newArrayListStringAdapter().nullSafe(); } if (rawType == Set.class && elementTypeIsString(type)) { return newLinkedHashSetStringAdapter().nullSafe(); } // No adapter for this type. return null; }
@Override public <T> T read(File file, Type type) { try { JsonAdapter<T> adapter = moshi.adapter(type); BufferedSource source = Okio.buffer(Okio.source(file)); T value; if (source.exhausted()) { value = null; } else { value = adapter.nullSafe().fromJson(source); } source.close(); return value; } catch (Exception e) { throw new ConverterException(e); } } }