@Override public @Nullable JsonAdapter<?> create(Type type, Set<? extends Annotation> annotations, Moshi moshi) { if ((type == Long.class || type == long.class) && Types.nextAnnotations(annotations, Uint64.class) != null) { return UINT64_JSON_ADAPTER; } Class<?> rawType = Types.getRawType(type); if (rawType == List.class && ((ParameterizedType) type).getActualTypeArguments()[0] == Long.class && Types.nextAnnotations(annotations, Uint64.class) != null) { return LIST_OF_UINT64_JSON_ADAPTER; } if (!annotations.isEmpty()) { return null; } if (rawType.equals(ByteString.class)) { return BYTE_STRING_JSON_ADAPTER; } if (Message.class.isAssignableFrom(rawType)) { return new MessageJsonAdapter(moshi, type); } return null; } }
@Override public @Nullable JsonAdapter<?> create( Type type, Set<? extends Annotation> annotations, Moshi moshi) { Set<? extends Annotation> delegateAnnotations = Types.nextAnnotations(annotations, Enveloped.class); if (delegateAnnotations == null) { return null; } Type envelope = Types.newParameterizedTypeWithOwner(EnvelopeJsonAdapter.class, Envelope.class, type); JsonAdapter<Envelope<?>> delegate = moshi.nextAdapter(this, envelope, delegateAnnotations); return new EnvelopeJsonAdapter(delegate); } };
@Override public JsonAdapter<?> create(Type type, Set<? extends Annotation> annotations, Moshi moshi) { Set<? extends Annotation> nextAnnotations = Types.nextAnnotations(annotations, FirstElement.class); if (nextAnnotations == null || !nextAnnotations.isEmpty()) return null; return new ElementAtJsonAdapter<>(type, moshi, 0); } };
@Override public JsonAdapter<?> create(Type type, Set<? extends Annotation> annotations, Moshi moshi) { Set<? extends Annotation> nextAnnotations = Types.nextAnnotations(annotations, LastElement.class); if (nextAnnotations == null || !nextAnnotations.isEmpty()) return null; return new LastElementJsonAdapter<>(type, moshi); } };
@Override public JsonAdapter<?> create(Type type, Set<? extends Annotation> annotations, Moshi moshi) { Set<? extends Annotation> nextAnnotations = Types.nextAnnotations(annotations, Transient.class); if (nextAnnotations == null) return null; return new TransientJsonAdapter<>(moshi.adapter(type, nextAnnotations), false, false); } };
@Override public JsonAdapter<?> create(Type type, Set<? extends Annotation> annotations, Moshi moshi) { Set<? extends Annotation> nextAnnotations = Types.nextAnnotations(annotations, DeserializeOnly.class); if (nextAnnotations == null) return null; return new TransientJsonAdapter<>(moshi.adapter(type, nextAnnotations), false, true); } };
@Override public JsonAdapter<?> create(Type type, Set<? extends Annotation> annotations, Moshi moshi) { Set<? extends Annotation> nextAnnotations = Types.nextAnnotations(annotations, FilterNulls.class); if (nextAnnotations == null || !nextAnnotations.isEmpty()) return null; Class<?> rawType = Types.getRawType(type); if (Collection.class.isAssignableFrom(rawType)) { return new FilterNullsJsonAdapter<>(moshi.adapter(type, nextAnnotations)); } return null; } };
@Override public JsonAdapter<?> create(Type type, Set<? extends Annotation> annotations, Moshi moshi) { Set<? extends Annotation> nextAnnotations = Types.nextAnnotations(annotations, SerializeOnlyNonEmpty.class); if (nextAnnotations == null) return null; Class<?> rawType = Types.getRawType(type); if (rawType.isArray() || Collection.class.isAssignableFrom(rawType) || Map.class.isAssignableFrom(rawType)) { return new SerializeOnlyNonEmptyJsonAdapter<>(moshi.adapter(type, nextAnnotations)); } return null; } };
@Override public JsonAdapter<?> create(Type type, Set<? extends Annotation> annotations, Moshi moshi) { Set<? extends Annotation> nextAnnotations = Types.nextAnnotations(annotations, SerializeNulls.class); if (nextAnnotations == null) return null; return moshi.adapter(type, nextAnnotations).serializeNulls(); } };
@Override public JsonAdapter<?> create(Type type, Set<? extends Annotation> annotations, Moshi moshi) { Set<? extends Annotation> nextAnnotations = Types.nextAnnotations(annotations, SerializeOnly.class); if (nextAnnotations == null) return null; return new TransientJsonAdapter<>(moshi.adapter(type, nextAnnotations), true, false); } };