@Override public @Nullable JsonAdapter<?> create( Type requestedType, Set<? extends Annotation> annotations, Moshi moshi) { if (type != requestedType) return null; JsonAdapter<T> delegate = moshi.nextAdapter(this, type, annotations); return new DefaultOnDataMismatchAdapter<>(delegate, defaultValue); } };
public void bind(Moshi moshi, JsonAdapter.Factory factory) { if (jsonAdapters.length > 0) { Type[] parameterTypes = method.getGenericParameterTypes(); Annotation[][] parameterAnnotations = method.getParameterAnnotations(); for (int i = adaptersOffset, size = parameterTypes.length; i < size; i++) { Type type = ((ParameterizedType) parameterTypes[i]).getActualTypeArguments()[0]; Set<? extends Annotation> jsonAnnotations = jsonAnnotations(parameterAnnotations[i]); jsonAdapters[i - adaptersOffset] = Types.equals(this.type, type) && annotations.equals(jsonAnnotations) ? moshi.nextAdapter(factory, type, jsonAnnotations) : moshi.adapter(type, jsonAnnotations); } } }
@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 void bind(Moshi moshi, JsonAdapter.Factory factory) { super.bind(moshi, factory); delegate = Types.equals(parameterTypes[0], returnType) && qualifierAnnotations.equals(returnTypeAnnotations) ? moshi.nextAdapter(factory, returnType, returnTypeAnnotations) : moshi.adapter(returnType, returnTypeAnnotations); }
@Override public void bind(Moshi moshi, JsonAdapter.Factory factory) { super.bind(moshi, factory); delegate = Types.equals(parameterTypes[0], returnType) && qualifierAnnotations.equals(returnTypeAnnotations) ? moshi.nextAdapter(factory, parameterTypes[0], qualifierAnnotations) : moshi.adapter(parameterTypes[0], qualifierAnnotations); }
if (toAdapter == null || fromAdapter == null) { try { delegate = moshi.nextAdapter(this, type, annotations); } catch (IllegalArgumentException e) { String missingAnnotation = toAdapter == null ? "@ToJson" : "@FromJson";
@Override public JsonAdapter<?> create(Type type, Set<? extends Annotation> annotations, Moshi moshi) { final JsonAdapter<Object> next = moshi.nextAdapter(this, type, annotations); return new JsonAdapter<Object>() { @Override public Object fromJson(JsonReader reader) throws IOException { throw new JsonDataException("Fail for all types"); } @Override public void toJson(JsonWriter writer, Object value) throws IOException { next.toJson(writer, value); } }; } })
public void bind(Moshi moshi, JsonAdapter.Factory factory) { if (jsonAdapters.length > 0) { Type[] parameterTypes = method.getGenericParameterTypes(); Annotation[][] parameterAnnotations = method.getParameterAnnotations(); for (int i = adaptersOffset, size = parameterTypes.length; i < size; i++) { Type type = ((ParameterizedType) parameterTypes[i]).getActualTypeArguments()[0]; Set<? extends Annotation> jsonAnnotations = jsonAnnotations(parameterAnnotations[i]); jsonAdapters[i - adaptersOffset] = Types.equals(this.type, type) && annotations.equals(jsonAnnotations) ? moshi.nextAdapter(factory, type, jsonAnnotations) : moshi.adapter(type, jsonAnnotations); } } }
@Override public JsonAdapter<?> create(Type requestedType, Set<? extends Annotation> annotations, Moshi moshi) { if (Types.equals(type, requestedType)) { JsonAdapter<T> delegate = moshi.nextAdapter(this, type, annotations); return new DefaultOnDataMismatchAdapter<>(delegate, defaultValue); } return null; } };
@Override public void bind(Moshi moshi, JsonAdapter.Factory factory) { super.bind(moshi, factory); delegate = Types.equals(parameterTypes[0], returnType) && qualifierAnnotations.equals(returnTypeAnnotations) ? moshi.nextAdapter(factory, returnType, returnTypeAnnotations) : moshi.adapter(returnType, returnTypeAnnotations); }
@Override public void bind(Moshi moshi, JsonAdapter.Factory factory) { super.bind(moshi, factory); delegate = Types.equals(parameterTypes[0], returnType) && qualifierAnnotations.equals(returnTypeAnnotations) ? moshi.nextAdapter(factory, parameterTypes[0], qualifierAnnotations) : moshi.adapter(parameterTypes[0], qualifierAnnotations); }
return null; JsonAdapter<List<Data>> listDelegate = moshi.nextAdapter(this, type, annotations); JsonAdapter<Data.Wrapper> wrapperDelegate = moshi.adapter(Data.Wrapper.class, annotations); return new DataUnwrapperAdapter(listDelegate, wrapperDelegate);
if (toAdapter == null || fromAdapter == null) { try { delegate = moshi.nextAdapter(this, type, annotations); } catch (IllegalArgumentException e) { String missingAnnotation = toAdapter == null ? "@ToJson" : "@FromJson";