com.squareup.moshi.Moshi.nextAdapter()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(5.4k)|赞(0)|评价(0)|浏览(127)

本文整理了Java中com.squareup.moshi.Moshi.nextAdapter()方法的一些代码示例,展示了Moshi.nextAdapter()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Moshi.nextAdapter()方法的具体详情如下:
包路径:com.squareup.moshi.Moshi
类名称:Moshi
方法名:nextAdapter

Moshi.nextAdapter介绍

暂无

代码示例

代码示例来源:origin: square/moshi

@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);
 }
};

代码示例来源:origin: square/moshi

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);
  }
 }
}

代码示例来源:origin: square/moshi

@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);
 }
};

代码示例来源:origin: square/moshi

@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);
}

代码示例来源:origin: square/moshi

@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);
}

代码示例来源:origin: square/moshi

if (toAdapter == null || fromAdapter == null) {
 try {
  delegate = moshi.nextAdapter(this, type, annotations);
 } catch (IllegalArgumentException e) {
  String missingAnnotation = toAdapter == null ? "@ToJson" : "@FromJson";

代码示例来源:origin: serj-lotutovici/moshi-lazy-adapters

@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);
   }
  };
 }
})

代码示例来源:origin: com.squareup.moshi/moshi

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);
  }
 }
}

代码示例来源:origin: serj-lotutovici/moshi-lazy-adapters

@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;
 }
};

代码示例来源:origin: com.squareup.moshi/moshi

@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);
}

代码示例来源:origin: com.squareup.moshi/moshi

@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);
}

代码示例来源:origin: stackoverflow.com

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);

代码示例来源:origin: com.squareup.moshi/moshi

if (toAdapter == null || fromAdapter == null) {
 try {
  delegate = moshi.nextAdapter(this, type, annotations);
 } catch (IllegalArgumentException e) {
  String missingAnnotation = toAdapter == null ? "@ToJson" : "@FromJson";

相关文章